SPI receiving

I got a lpc2148 test board and connected, is a AD7656, a 6-channel simultaneous sampling a/d converter, through SPI.

To initiate the AD7656 I had to set several output pins and one input pin. The input pin is used to see if a conversion is finished.

This is working properly.

Now my problem.

How do I have to read the data on the MISO pin, which is send by the ADC?

Here is my code to setup SPI.

   PINSEL0 = 0x00001500;

   S0SPCR   = 0x00A4;	
   S0SPCCR  = 0x08;

I tried to write a byte to start the clock and see if I could read something,

but that didn’t work.

Maybe someone can help me and I’m overlooking something or

someone could provide me a link/tutorial how to receive data with the SPI.

Thanks in advance.

Maurice

In the tutorials that I mentioned in a different thread you started, I also do SPI comms in both directions on the LPC2148. That should help you out. If you’re just trying to check if you have communications, start by setting the loopback bit. Then send a byte and see if you can read it in the RX FIFO. If you can, then you have SPI working internally and then clear the loopback bit and test the SPI using a hardware loopback (i.e., wire MOSI and MISO together and do the same test as above). If you can still read the same byte you sent, then you’re good as far as MOSI and MISO. All that will be left is to make sure that you have set your CLK and CS*/SS* pins up properly.

The SPI-bus is now working fine, when I send data

over the MOSI line, which is connected with the MISO line,

I see the data coming in again.

But now the following:

When I want to get 48 bits of data on the MISO pin, which is send by the ADC (AD7656),

do I have to send 3 times a dummy byte to update S0SPDR because it is 16 bits or is there another way.

On the internet I can’t exactly find what I’m looking for.

Thanks in advance

You have to send a dummy byte for every byte you want to receive.

Leon

Do you have SPI on the LPC2148 configured as master or slave? If you have it in master, it’s pretty easy to read as many bytes as you want in a row. I also do this in nrf24l01.c in the tutorials. You just send out as many bytes as you want to receive, and poll your receiving data register to see when it has valid data. Then you buffer the data as you get it (each time you receive a new byte, the old one will be overwritten, so you have to save each one as it comes in).

If you’re in slave mode, you’re limited to getting no more than 16 bytes at a time (AFAIK).

Thanks for your replies, but I already got it to work.

Like Leon said, I had to send a dummy byte for every byte I want to retrieve. But this wasn’t what I was doing wrong.

I did something wrong with the settings of the function generator,

which gives me the signal for the ad converter, so it looked as if it was not working on my oscilloscope.

Thanks anyway.