EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Problem with SPI1 on LPC2119

Started by irafalovsky August 8, 2006
--- In l..., "subscriptions@..."
wrote:

> There is no way for the slave HW to know how many bits the master
>uses per word so it cannot have any dependancies on word size.

I thought that the transition of the slave select signal identified
the end of the current word, and reset the slave state machine to
begin the next word???????????????

--Dave

An Engineer's Guide to the LPC2100 Series

>Original Message:
>-----------------
>From: derbaier
>--- In l..., "subscriptions@..."
> wrote:
>
>> There is no way for the slave HW to know how many bits the master
>>uses per word so it cannot have any dependancies on word size.
>
>I thought that the transition of the slave select signal identified
>the end of the current word, and reset the slave state machine to
>begin the next word???????????????

Nope, Chip select is done on a frame basis. Of the three devices I've got
on one board at the moment, one has a frame size of 12 bits, one of 24 bits
and one is an indeterminate multiple of 8 bits (the frame size depends on
how many 8 bit bytes I want to read/write at once). All controlled via the
Philips inital SPI with a fixed 8 bit word size. If you toggle the slave
select between words you will definitely fail.

Robert
--------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
I wonder, what mechanism is used to "deselect the slave" if the pin
for chipselect is not controlled by SPI but by a user program, is
that some sort of internal workings of SPI implementation on LPC?

I didn't see anything like that in documentation...

--- In l..., "derbaier" wrote:
>
> --- In l..., "irafalovsky" wrote:
> >
> > It seems that LPC2138/LPC2148 have SPI1 configured as SSP with
> > buffered data register, which manual for LPC2119 has no
mentioning
> > of... In fact, first two bits of S1SPCR register are defined as
> > reserved, whereas first two bits of this register for 2138/2148
> > defind as data size...
> >
> > --- In l..., "derbaier" wrote:
>
> In the LPC2138/48 there two SPIs. SPI0 is "Compliant with Serial
> Peripheral Interface (SPI) specification." , whereas SPI1 is
> "Compatible with Motorola SPI, 4-wire TI SSI, and National
> Semiconductor Microwire
> buses." In SPI0 bits 11:8 of S0SPCR control the units of transfer,
> while bits 3:0 of SSPCR0 in SPI1 control the units of transfer.
There
> is also an 8 word/frame FIFO in SPI1 which is 16 bits wide, as is
the
> data register of SPI0. However, the data register of the LPC2119 is
> only 8 bits wide, so transfers have to be in units of 8 bits. You
> should be able to combine as many 8 bit units as needed if both
sides
> of the transfer agree, since the hardware state machine in the
LPC2119
> is going to deslect the slave after each 8 bit unit.
> That is all in my interpretation of course!
>
> -- Dave
>
>Original Message:
>-----------------
>From: irafalovsky

>I wonder, what mechanism is used to "deselect the slave" if the pin
>for chipselect is not controlled by SPI but by a user program, is
>that some sort of internal workings of SPI implementation on LPC?

That's your job. You select the slave before starting the frame and
deselect it after frame end.

Robert
--------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
--- In l..., "subscriptions@..."
wrote:
>
> >Original Message:
> >-----------------
> >From: derbaier
> >--- In l..., "subscriptions@"
> > wrote:
> >
> >> There is no way for the slave HW to know how many bits the master
> >>uses per word so it cannot have any dependancies on word size.
> >
> >I thought that the transition of the slave select signal identified
> >the end of the current word, and reset the slave state machine to
> >begin the next word???????????????
>
> Nope, Chip select is done on a frame basis. Of the three devices
I've got
> on one board at the moment, one has a frame size of 12 bits, one of
24 bits
> and one is an indeterminate multiple of 8 bits (the frame size
depends on
> how many 8 bit bytes I want to read/write at once). All controlled
via the
> Philips inital SPI with a fixed 8 bit word size. If you toggle the
slave
> select between words you will definitely fail.
>
> Robert
>
But the LPC2119 does toggle slave select every 8 bits, which indicates
to me that it's internal state machine is resetting regardless of what
the peripheral is doing?

I hope that Mr. Irafalovsky posts his final outcome, because now my
curiosity is really arroused.

-- Dave
Would you be willing to share a code example with the group or send
it to me? We're banging our heads on the wall here... :-)

--- In l..., "subscriptions@..."
wrote:
>
> >Original Message:
> >-----------------
> >From: derbaier
> >--- In l..., "subscriptions@"
> > wrote:
> >
> >> There is no way for the slave HW to know how many bits the
master
> >>uses per word so it cannot have any dependancies on word size.
> >
> >I thought that the transition of the slave select signal
identified
> >the end of the current word, and reset the slave state machine to
> >begin the next word???????????????
>
> Nope, Chip select is done on a frame basis. Of the three devices
I've got
> on one board at the moment, one has a frame size of 12 bits, one
of 24 bits
> and one is an indeterminate multiple of 8 bits (the frame size
depends on
> how many 8 bit bytes I want to read/write at once). All
controlled via the
> Philips inital SPI with a fixed 8 bit word size. If you toggle
the slave
> select between words you will definitely fail.
>
> Robert
> -------------------------------
-
> mail2web - Check your email from the web at
> http://mail2web.com/ .
>
>Original Message:
>-----------------
>From: irafalovsky
>
>Would you be willing to share a code example with the group or send
>it to me? We're banging our heads on the wall here... :-)

Check the newlib-lpc stuff at http://www.aeolusdevelopment.com

It's only for SPI0, developed originally for LPC2104/5/6 so it has none of
this fancy word size selection etc... ;)

There is an FRAM driver though and that does use the spi driver to to the
underlying work. Since the structure is meant to be built on to abstract
the SPI functionality away from the device driver it's not the clearest
exposition of the SPI itself. It is, however, commented.

Robert

--------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
>Original Message:
>-----------------
>From: derbaier
> wrote:
>>
>> Nope, Chip select is done on a frame basis. Of the three devices I've
got
>> on one board at the moment, one has a frame size of 12 bits, one of 24
bits
>> and one is an indeterminate multiple of 8 bits (the frame size depends on
>> how many 8 bit bytes I want to read/write at once). All controlled via
the
>> Philips inital SPI with a fixed 8 bit word size. If you toggle the slave
>> select between words you will definitely fail.
>
>But the LPC2119 does toggle slave select every 8 bits, which indicates
>to me that it's internal state machine is resetting regardless of what
>the peripheral is doing?

If that's the case it's broken. Don't use the automatic slave select. If
it toggles every word it will work with only a small number of slave
devices.

Robert
--------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
--- In l..., "subscriptions@..."
wrote:
>
> >Original Message:
> >-----------------
> >From: derbaier
> > wrote:
> >>
> >> Nope, Chip select is done on a frame basis. Of the three devices
I've
> got
> >> on one board at the moment, one has a frame size of 12 bits, one
of 24
> bits
> >> and one is an indeterminate multiple of 8 bits (the frame size
depends on
> >> how many 8 bit bytes I want to read/write at once). All
controlled via
> the
> >> Philips inital SPI with a fixed 8 bit word size. If you toggle
the slave
> >> select between words you will definitely fail.
> >
> >But the LPC2119 does toggle slave select every 8 bits, which indicates
> >to me that it's internal state machine is resetting regardless of what
> >the peripheral is doing?
>
> If that's the case it's broken. Don't use the automatic slave
select. If
> it toggles every word it will work with only a small number of slave
> devices.
>
> Robert
>

Isn't that what this thread is all about???

-- Dave
The code that Alan presented should be correct...however, you
absolutely MUST change the double ampersand (&&) to a single one (&)
in your wait loop.

For example,

while(!(IOPIN0 && (1 << 22))){;;} // Wait for Data Ready

must be replaced with...

while(!(IOPIN0 & (1 << 22))){;;} // Wait for Data Ready

In the top case you will never wait since && means a logical 'AND'.
Therefore (1<<22) will always evaluate to non-zero (therefore
TRUE)...and its very likely that at least one of the bits in the read
of IOPIN0 will be high thus making that part TRUE and the whole
expression will evaluate to TRUE...which after you negate with the !
out in front will cause you to leave the loop immediately (which is
not what you intended for it to do).

What you mean to do with your expression is to MASK the bit of
interest (in this case bit 22) with a read of IOPIN0...that's what
the single & is for...take a moment in any C reference to review the
meaning of the operators and you'll be back on track.

I took a quick glance at the datasheet for the sensor you are using
and the Data Ready signal may not be asserted for 500 microSeconds in
the best case and could take as long as 60 milliSeconds in the worst
case (based on the Period Select setting...which I'm not sure which
one you are using). Since your wait loop never actually waits, you
will NEVER expect to see valid data! Even if you have the SPI and
chip select configured properly you will NEVER see valid data because
you are not actually waiting for it.

I'm sure you've checked the direction of Pin 22 but just for sanity
make sure you have it configured as an input also. You may want to
pay fairly close attention to this pin and whether or not there is an
internal pull-up enabled on it. It's very unlikely, but perhaps the
sensor's Data Ready output isn't strong enough to pull the line low
when data is not yet ready. Maybe just double check the levels to
which the pin is toggling and see that they are at expected levels.

I hope this helps you get things working...I know what it feels like
to be in pain sometimes.

Best regards,
Ryan.
--- In l..., "irafalovsky" wrote:
>
> Would you be willing to share a code example with the group or send
> it to me? We're banging our heads on the wall here... :-)
>
> --- In l..., "subscriptions@"
> wrote:
> >
> >
> >
> > >Original Message:
> > >-----------------
> > >From: derbaier
> > >--- In l..., "subscriptions@"
> > > wrote:
> > >
> > >> There is no way for the slave HW to know how many bits the
> master
> > >>uses per word so it cannot have any dependancies on word size.
> > >
> > >I thought that the transition of the slave select signal
> identified
> > >the end of the current word, and reset the slave state machine to
> > >begin the next word???????????????
> >
> > Nope, Chip select is done on a frame basis. Of the three devices
> I've got
> > on one board at the moment, one has a frame size of 12 bits, one
> of 24 bits
> > and one is an indeterminate multiple of 8 bits (the frame size
> depends on
> > how many 8 bit bytes I want to read/write at once). All
> controlled via the
> > Philips inital SPI with a fixed 8 bit word size. If you toggle
> the slave
> > select between words you will definitely fail.
> >
> > Robert
> >
> >
> > ------------------------------
-
> -
> > mail2web - Check your email from the web at
> > http://mail2web.com/ .
>

Memfault Beyond the Launch