EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

LPC21xx SSP controller as SPI master and slave

Started by ashwin athani February 14, 2008
Hi all,

We have been trying to use the SSP controller on the LPC2148 (master) and LPC2138 (slave) as SPI.

The hardware design is such that LPC2148 and LPC2138 are connected over the SSP interface. There are some sensors connected to the LPC2138 and the LPC2148 has to read these sensor values over SPI.

Typically while developing the driver for any interface you would have the counter part driver ready. for example if you are interfacing and EEPROM which communicates over SPI the slave driver is implemented in the EEPROM and you can be assured that if there are any issues then it has to be with your driver (unless there are hardware problem). But we are attempting to develop both the master and slave driver at the same time.

I will just try and explain the problem that we are facing. Here we go!
1. When we try to only send from master and receive at slave we have no issues. The data comes along fine.

Master Code:

init_spi();
while(1)
{
for(i=0;i<100;i++)
{
spi_send(byte, 1);
}
}

Slave Code:

init_spi();
while(1)
{
for(i=0;i<100;i++)
{
spi_receive(byte, 1);
}
}

2. When we try to only send from Slave and receive at Master the data goes through fine.

Master Code:

init_spi();
while(1)
{
for(i=0;i<100;i++)
{
spi_receive(byte, 1);
}
}

Slave Code:

init_spi();
while(1)
{
for(i=0;i<100;i++)
{
spi_send(byte, 1);
}
}

Actually, the problem that we are facing is:
Master Code:

init_spi();
while(1)
{
for(i=0;i<100;i++)
{
spi_receive(byte, 1);
}

for(i=0;i<100;i++)
{
spi_send(byte, 1);
}
}

Slave Code:

init_spi();
while(1)
{
for(i=0;i<100;i++)
{
spi_send(byte, 1);
}
for(i=0;i<100;i++)
{
spi_receive(byte, 1);
}

}

When we attempt to send few bytes from the master and receive it at the slave and then send few bytes from the slave to master, sometimes we get erroneous data at the master (It can be the slave as well). But the good part is that this erroneous byte is the one that the slave writes (dummy write) for reading.Both the drivers are in being implemented in polled mode.

Just wanted to check if someone has worked on the SSP controller (as SPI master and slave). I did see a post on the group that one person claimed to have got the SSP to work as SPI slave. Just wondering if you could share your ideas/problems encountered while implementing the same. If you could share the code it would be great.

Thanks for reading so far :)

Warm regards
Ashwin

---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.

An Engineer's Guide to the LPC2100 Series


The 2024 Embedded Online Conference