Hi,
in a project we have cc2538 that is slave on SPI bus and it have to receive command from SPI master chip.
I design a protocol based on two operation: write operation is for communication master-to-slave, while read is for slave-to-master operation (means slave as some output for master).
The protocol works in this way:
- the master initiate the communication clearing CS line, sending 2byte with operation code and 1byte with length
- slave react:
- if is a write operation 4th to len-th byte will be received from slave and do what have to do.
- if is a read operation 4th to len-th byte is from slave to master
- master end the communication rising the CS line
I 'm testing the protocol and implementation simulating the master with another cc2538, but this is just for develope purpose. I choose to catch CS line with an GPIO interrupt to be able to do something to prepare and terminate the operation. I configure SSI with Motorola frame format, SPO=0 SPH=1, 8 bit word. the baud rate is 1Mhz.
My implementation with write operation works fine, I have some problem in read operations.
I wasn't able to answer correctly from slave to master, on cc2538 I do:
- GPIO interrupt catch CS line falling edge and enable SPI
- on SSI ISR receive and elaborate comunication header:
- move bytes from RxFifo to a local buffer if 3 bytes are in buffer:
- if is a read operation and txfifo is not full: copy from a position in RAM n-byte in TxFifo
- if is a write operation wait all bytes is tranfered
- move bytes from RxFifo to a local buffer if 3 bytes are in buffer:
- master clock for n bytes:
- if is a read operation master transmit n null byte (0x00) slave should transfer what I put in TxFifo
- if is a write operation master transmit n byte of payload
- GPIO interrupt catch CS line rising edge, disable SPI and prepare for new operation
The problem is at point 3a: the slave doesn't send the bytes I put in fifo.
Looks the Txfifo was write only when chip select is not active. The result I have is: first time it send all 0x00, second time the answer of first operation, third time the answer of second.
I thought I was to slow feeding the Txfifo I insert a delay of 500us between each byte in my mater simulator. It doesn't solve.
Can anybody help me understand how TxFifo works? can uDMA helps?
Another question that I have to answer soon: is it possible to empty TxFifo (dropping the contents)?
Davide