I am working on a big project where I will have 9 PSoC3 devices working together.
A short description of the project:
8 PSoC3 devices to "read", amplify, filter and store locally 8 analog sensors.
1 PSoC3 device to rule them all! This will be the master SPI and the rest will be slaves.
The master has to periodically acquire the data gathered from the 8 slaves and store them on an SD Card. Hopefully the SPI has to transmit with a bit rate of 8 MHz.
To test the SPI I am using two CY8CKIT-001 and trying to transmit 4 bytes both ways. I also read somewhere that SPI communication is not very good for long wires so to make it as short as possible I am connecting the ports of the dev kit directly like this:
I have also connected the grounds of the two dev kits together.
I have tried several different setups with DMA transfer and with ISR but nothing worked. So, now I am trying to make it as simple as possible. Just send and receive 4 bytes on each side. I don't think it gets any simpler than that. I have attatched the code on a txt file.
Both SPIs are configured in Mode3 (11), with MSB first @ 1kHz (lowest possible for the test. In the final project I want it to run around 8MHz).
I am reseting the Slave first and 2-3 seconds later the Master.
So in theory it should work like this:
1. The slave is reset and initialized
2. Slave places the 1st byte in the transmit buffer
3. Slave waits until a byte is received
4. Master is reset and initialized
5. Master sends 1 byte
5. Master waits until the byte is transmitted
6. Slave and master both read the received bytes
7. Master waits for 50ms (I have tried higher values also with same results)
8. Slave prints the byte on LCD and places the next byte to be transmitted on the TX buffer
9. Slave waits until a byte is received
10. Master sends next byte
and so on... until 4 bytes have been exchanged.
It should work properly, right? Well it doesn't.
On the Slave LCD I get from 2 to 4 bytes printed (usually 2) with only the first byte being always correct ("a").
On the Master I get 4 bytes usually with 1 random byte being correct but never all of them.
It's driving me crazy! I am 100% I am missing sth but I can't find out what.
I'm buying beer to whoever helps me with this :P
Is it possible to use two master SPI components on the same design? So that I can talk to 2 slaves on the same time.
main.txt.zip 898 bytes