Content originally posted in LPCWare by jcc273 on Fri Jul 26 14:51:20 MST 2013
So yeah im pretty sure what it does when underrun is after transmitting the last byte it progresses to the next position in the FIFO (Ring Buffer) and just keeps transmitting that until you right more data at which point it will process the byte you put into that position then move to the next one.
My solution was this:
When buffer is half empty interrupt: if data left then put more data in and clear counter, else if counter > 1 then disable half empty interrupt, else stuff 0's and inc counter.
so that way before i stop filling the buffer i make sure it has been filled with 0s. if i was to get more data along the way then when half empty it puts that instead and clears the counter. So then when i am out of data it will be transmitting 0s always. when i get more data i simply stuff the buffer then flip the interrupt back on and then since it is just waiting transmitting the same byte i have no delay before it starts transmitting my data.
This probably wouldn't have been such a mess if i was using conventional command response spi, but i wanted to be able to stream commands and just let the responses come as they may (I have an int line from slave that is pulled low when slave has data to send in case of no commands).
Good to go : ).