2024-06-28 03:49 PM - edited 2024-06-28 03:50 PM
Hi everyone! I was hoping to get some help on a function I've made which is called by timer to write to a DAC which takes 24 bit bytes, which I send in 8 bit chunks. I wanted to make my own function because the HAL_SPI_Transmit is oretty overhead heavy and slow to execute.
The thing I can't figure out is that in the below function, if I comment out the line where I wait for the TXE flag bit to set, meaning the FIFO is empty, the funciton works BUT, if I try and execute that function TWICE in the same TIM function call, it does not work. So, something is happening between calls of the TIM callback that is somehow allowing me to write to SPI again, but this doesn't seem to happen if I wait for it in my function with a while(); If I uncomment the line with a while(!((SPI->SR)&(1<<1)){}; then the thing hangs up and sits at that line forever.
I SUSPECT that I'm somehow leaving 8bits in the FIFO after my 24 bit sequence and it just stays that way forever and hangs on my line discussed above, but I don't know. Any help would be fantastically appreciated! From what I understand there is NO way to force a clear on the FIFO, so I need some otherway to do this. I couldn't figure out from the HAL_SPI_Write() function how they are doing it even though my funciton below is virtually copy and paste from the relevent parts of that function.