SPI Slave TX Underrun

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by jcc273 on Fri Jul 26 13:04:46 MST 2013
I figured this has to be documented somewhere but i can't seem to find it.  What exactly happens if i am running as an SPI Slave on the LPC1788 and my TX buffer is underrun?

By testing i think i have figured out what happens, but it is undesirable behavior.

What i am seeing in testing is this (SPI_MODE_1):

Master sends LPC a 5 Byte Message:  t,e,s,t,Line Break
During this transmission the LPC slave sends 0's
Master then clocks out 10 lines for the LPC to respond.  It is currently just reflecting so it sends t,e,s,t,Line Break back followed by 5 0's.

The process is then repeated, only the slave sends back:  t,e,s,t,Line Break,s,s,s,s,s
then the next time the slave sends data during the request: s,s,s,s,s
and again during the response:  t,e,s,t,Line Break,s,s,s,s,s

If i change the test string the result is different, so considering it is an 8-byte fifo it would appear that it wraps around and when the last byte is transmitted it automatically loads the next byte and keeps sending that until new data is written:

FIFO:  1   2   3   4   5   6    7   8
       t   e   s   t   _   ^/t  e   s
       t   _   ^/t e   s   t    _   ^/t
       e   s   t   _   ^/t...............

Where i put the arrows here is where it hits the end of the buffer and just seems to transmit whatever is in that position already, which is why i see s in all the blanks after a couple iterations.

What i would like to do is either:

A - Keep sending the last byte that was sent until new data is ready
or B - Disable sending any data until data is ready.

Now i see there is a Slave Data Disable that would appear to work for me.  Simply disable sending any data if there is none to send, HOWEVER, there is no interrupt for when the TX FIFO is empty, so i wouldn't know when to flag this disable : /. 

So any additional information that may help me would be greatly appreciated!  Right now the best thing i can think of is to keep putting data into the tx buffer when it is half empty to prevent the underrun altogether and i could just put 0's in if no data is ready, but that seems wasteful to me.