SPI Slave behaviour

06 Oct 2011

I am trying to get a slave working.

I have 2 mbed devices one configured as Master and other slave. I am using DIP 5 6 7 8 for my SPI.

When I use the mbed class SPISlave this works great in polling mode (interrupt do not work... thats a different problem).

Now I used a driver uploaded by someone which is the same driver given by NXP. I configured the same port with that its not working. I see on the scope that all the spi signals drop to half in peak to peak some are biased up by 1.7 V. These signals are fine if I use SPISlave.

I dumped the all the registers they are exactly same here is the dump

With SPISlave

PCONP - 0x052887DE PCLK0 - 0x001C0040 PCLK1 - 0x00010000 SPCR - 0x00000000 SPSR - 0x00000000 SPCCR - 0x00000000 PINSEL0 - 0x005AA050 PINMOD0 - 0x00AAA0A0 Int REg = 0x00000000

With my driver

0x052887DE -PCONP 0x000C0000 -PCLK0 0x00000000 -PCLK1 0x00000000 -SPCR 0x00000000 -SPSR 0x00000000 -SPCCR 0x005AA000 -PINSEL0 0x000AA000 -PINMOD0

I do not see whats the difference. All the configurations are same.

Have anyone seen this problem or know why please let me know.

Regards, Shankar

06 Oct 2011

The basic SPI system allows multiple slaves to be connected to a single master. Electrically for this to work the slave transmit port (MISO) has to assume an open-collector form when not sending data.

Unless there is some form of pullup to VCC, the signal will fall to half amplitude when set to be open-collector.

Page 402 of the LPC1768 User Manual states, as part of the MISO pin description "When a slave device is not selected, the slave drives the signal high-impedance"

It is possible using PINMODE to configure the pin as open-collector with pull-up. This avoids the half amplitude signal effect.

06 Oct 2011

Thanks for the reply. I did try to configure as pullup. It did not change anything.

if I use mbed library it works. I dumped the setting from the mbed lib and configured my code with the same configuration. It do not work. What is special mbed is doing that I am missing?

Regards, Shankar

06 Oct 2011

I only use mbed libraries for first protos. After that I go to all 'C' code

Here is my code for Master and Slave initialization and data transfer. /media/uploads/JohnDH/spi.txt

06 Oct 2011

thanks... It pointed me to use the SSP interface.

The reason I am implementing my own driver is interrupt do not work woth SPISlave class, I need that to work with my prototype.

I will try using SSP. Does the legacy SPI port do not work on p0_6 - p0_9 pins?

06 Oct 2011

As I understand it legacy SPI0 and SSP0 use the same LPC1768 pins. P0.6 to P0.9 are for the SSP1 port. If you want to use those pins then both ports must be SSP. You cannot have one legacy SPI and the other SSP

06 Oct 2011

Thanks that answers all my questions!!!

06 Oct 2011

It Worked!! thanks for the great help :)

07 Oct 2011

I have made an interrupt driven slave SPI class. It is very specific for one application (I won a DE award in the mbed design challenge with it), but some of the code might be helpful, see http://mbed.org/users/DeMein/programs/MMEx_Challenge/ln9qcp

07 Oct 2011

Thanks... thats helpful code... is SSEL have to be toggled or can it be left low in single slave configuration?

08 Oct 2011

I do think that the SPI protocol requires that the SSEL line is toggled between transfers, otherwise the slave does not know that a new transfer is imminent.

12 Oct 2011

I agree with you. but it do not have to be edge triggered. It could be level triggered. I mean if I hold it low all the time, slave is selected all the time. This did not work. I had to make a transition from high to low to get this to work.

05 Dec 2012

hii you said you have programmed two mbed's in spi one as master and other as slave.. can you please post your master and slave code. thanks