Reply by Ananda Regmi June 14, 20112011-06-14
Hello,

Is there a special provision in LPC2106 to read the second byte from a SPI
slave. I could not find any flags to indicate that data byte is ready.

Here's my scenario. I have a A/D converter hooked up to the SPI interface of
LPC2106. When I send a 8-bit command, the ADC sends back 16-bit data. I
think I am reading the first byte fine. When I read the data register
expecting the next byte, it still has the old byte.

Is there a way to tell the SPI that it is supposed to read 16-bits. SPI data
register is 8-bit. How to tell to it to wait for me to read the first 8-bit
and then send the clock to receive the next 8-bit.

Reading through LPC2106 manual, it seems like it is impossible to read
16-bit data from slave. But, I don't want to believe that is true.

BTW: I have it working with bit-banging. Changing the implementation to use
processors register for cleaner code. I don't know if it's worth it.

Regards,
Ananda

An Engineer's Guide to the LPC2100 Series

Reply by "Randy M. Dumse" June 14, 20112011-06-14
Ananda Regmi said: Tuesday, June 14, 2011 5:15 PM
> Here's my scenario. I have a A/D converter hooked
> up to the SPI interface of LPC2106. When I send
> a 8-bit command, the ADC sends back 16-bit data.
> I think I am reading the first byte fine. When
> I read the data register expecting the next byte,
> it still has the old byte.

An SPI can not send 8 bits and receive 16-bits. To receive
16-bits you have to send 16-bits. The single master clock shifts
both sets of data. Your answer will depend more on you're a/D
converter than anything now. Send you're 8-bit command, take the
first 8-bits of data, and then send an 8-bits of dummy (00 or FF
or whatever the A/D will take) and you will get the second
8-bits from the A/D then.

Randy

Reply by Paul Curtis June 14, 20112011-06-14
On 14 Jun 2011, at 23:14, Ananda Regmi wrote:

> Hello,
>
> Is there a special provision in LPC2106 to read the second byte from a SPI slave. I could not find any flags to indicate that data byte is ready.
>
> Here's my scenario. I have a A/D converter hooked up to the SPI interface of LPC2106. When I send a 8-bit command, the ADC sends back 16-bit data. I think I am reading the first byte fine. When I read the data register expecting the next byte, it still has the old byte.
>
> Is there a way to tell the SPI that it is supposed to read 16-bits. SPI data register is 8-bit. How to tell to it to wait for me to read the first 8-bit and then send the clock to receive the next 8-bit.

You send another byte as the SPI master controls the clock. Sending the byte provides the clocks. Send 0xFF. Then read.

>
> Reading through LPC2106 manual, it seems like it is impossible to read 16-bit data from slave. But, I don't want to believe that is true.

Need another eight bits? Send another eight clocks.

>
> BTW: I have it working with bit-banging. Changing the implementation to use processors register for cleaner code. I don't know if it's worth it.

Hardware SPI is always worth it.

-- Paul.
Reply by Ananda Regmi June 14, 20112011-06-14
Thanks Paul...
Thanks Alex..
Thanks Randy.

Yes you all are right. I needed to send more bytes. I am interfacing with
AD7709. First I need to send a byte to configure it to read. It won't start
transmitting the data until it received the complete command. So, I could
not read the data register immediately after sending the command. Then, I
had to send two dummy bytes to generate the clock and I received the two
bytes.

Thanks a lot.

-Ananda

On Tue, Jun 14, 2011 at 5:02 PM, Randy M. Dumse wrote:

> Ananda Regmi said: Tuesday, June 14, 2011 5:15 PM
>
> > Here's my scenario. I have a A/D converter hooked
> > up to the SPI interface of LPC2106. When I send
> > a 8-bit command, the ADC sends back 16-bit data.
> > I think I am reading the first byte fine. When
> > I read the data register expecting the next byte,
> > it still has the old byte.
>
> An SPI can not send 8 bits and receive 16-bits. To receive
> 16-bits you have to send 16-bits. The single master clock shifts
> both sets of data. Your answer will depend more on you're a/D
> converter than anything now. Send you're 8-bit command, take the
> first 8-bits of data, and then send an 8-bits of dummy (00 or FF
> or whatever the A/D will take) and you will get the second
> 8-bits from the A/D then.
>
> Randy
>
>
>
Reply by Alexan_e June 14, 20112011-06-14
Another note is that when you send 8bit using spi then you also receive 8bit (in each clock you send a bit and receive one bit), there is no way to send 8bit and receive 16bit so you are searching for the second half of the 16bit result that you haven't received.
To receive 16bits you have to send 16bits so send 8bits twice

Alex

----- Original Message -----
From: Alexan_e
To: l...
Sent: Wednesday, June 15, 2011 1:35 AM
Subject: Re: [lpc2000] LPC2106 SPI Master Receive 16-bits of data From Slave

The 16bit spi is only possible with LPC2106/01,
If you set SPCR for 16 bit spi by setting bit2=1 and bits11:800 then you will get a 16 bit result in the SPDR register.

If you have LPC2106 then the transfer width is fixed to 8bit.

Alex

----- Original Message -----
From: Ananda Regmi
To: l...
Sent: Wednesday, June 15, 2011 1:14 AM
Subject: [lpc2000] LPC2106 SPI Master Receive 16-bits of data From Slave

Hello,

Is there a special provision in LPC2106 to read the second byte from a SPI slave. I could not find any flags to indicate that data byte is ready.

Here's my scenario. I have a A/D converter hooked up to the SPI interface of LPC2106. When I send a 8-bit command, the ADC sends back 16-bit data. I think I am reading the first byte fine. When I read the data register expecting the next byte, it still has the old byte.

Is there a way to tell the SPI that it is supposed to read 16-bits. SPI data register is 8-bit. How to tell to it to wait for me to read the first 8-bit and then send the clock to receive the next 8-bit.

Reading through LPC2106 manual, it seems like it is impossible to read 16-bit data from slave. But, I don't want to believe that is true.

BTW: I have it working with bit-banging. Changing the implementation to use processors register for cleaner code. I don't know if it's worth it.

Regards,
Ananda
Reply by Alexan_e June 14, 20112011-06-14
The 16bit spi is only possible with LPC2106/01,
If you set SPCR for 16 bit spi by setting bit2=1 and bits11:800 then you will get a 16 bit result in the SPDR register.

If you have LPC2106 then the transfer width is fixed to 8bit.

Alex

----- Original Message -----
From: Ananda Regmi
To: l...
Sent: Wednesday, June 15, 2011 1:14 AM
Subject: [lpc2000] LPC2106 SPI Master Receive 16-bits of data From Slave

Hello,

Is there a special provision in LPC2106 to read the second byte from a SPI slave. I could not find any flags to indicate that data byte is ready.

Here's my scenario. I have a A/D converter hooked up to the SPI interface of LPC2106. When I send a 8-bit command, the ADC sends back 16-bit data. I think I am reading the first byte fine. When I read the data register expecting the next byte, it still has the old byte.

Is there a way to tell the SPI that it is supposed to read 16-bits. SPI data register is 8-bit. How to tell to it to wait for me to read the first 8-bit and then send the clock to receive the next 8-bit.

Reading through LPC2106 manual, it seems like it is impossible to read 16-bit data from slave. But, I don't want to believe that is true.

BTW: I have it working with bit-banging. Changing the implementation to use processors register for cleaner code. I don't know if it's worth it.

Regards,
Ananda