ΣSigmaStudio Ask AI Русский Log in

SPI slave mode work incorrectly, need example code

Processors & DSP robin.hu May 27, 2010 00:00 2 replies Original on forum ↗
Subscribe
robin.hu Question
May 27, 2010 00:00

I am trying to work out an example that can establish data link between BF518 and another chip via SPI.

1) BF518 SPI0 work in slave mode, the other chip is SPI master.

2) SCK is input to BF518, about 10kHz, this clock is always exist.

3) BF518 SPI0 MISO is output.

4) The master(another chip) can not generate SSEL, so I have to use BF518's GPIO for its own SPI0-SS control

I use core polling mechanism to send bytes after pull down a GPIO to assert BF518-SPI0-SS, and then try to continuously transmit data, but found the bits were wrong after the first word was transfered(with SCOPE).

BTW, I am using BF518 EZKIT LITE.

robin.hu Reply
May 29, 2010 00:00

For test purpose, when I use BF518's own timer to output a clock for the SPI, the SPI slave work correctly, but if I use another chip's SPI clock, then BF518 can not output bits stream correctly.

Please coments and provide your help.

jobo23 Reply
Jun 28, 2010 00:00

It sounds to me like your control for the slave-select line isn't meeting the required timing specifications for the slave-select input when the external clock is asynchronous to the Blackfin (specifically, the tSDSCI spec in the SPI Slave Timing parameters). Since the GP timer output that you use to test the SPI as a slave is synchronous to the internal System Clock (and therefore also to the SPI clock), you may be removing this timing dependency. This is especially true if you enable the SPI before the timer in your test code.

If the host device with no control over the /SPISS only provides data when it also provides a clock, then your best bet is probably to just connect the /SPISS signal to GND through a resistor...that way, the Blackfin SPI configured as a slave will always respond when it sees that SCK signal coming in (provided the SPI has been properly initalized in the PORT_FER, PORT_MUX, and SPI_CTL registers to be enabled as a slave). However, even in this scenario, a problem arises if the host device is already transmitting something when the SPI is first enabled by the Blackfin, in which case you'll need some other external handshaking with the host to signal when the Blackfin is ready to start receiving. Does the host device have any sort of WAIT functionality?? If so, you could attach that to a GPIO with a termination resistor to the ACTIVE state, which you would then drive to the INACTIVE state via a GPIO output after you've enabled the SPI on the Blackfin side.