I am working on an interrupt handler with a hardware design team and we are trying to figure out where the error is. I am reading a chip on the 5 kHz SPI bus. The chip loads 4 bytes and starts data output.
My interrupt handler wakes up and reads 4 bytes from the SPI bus and saves the data in the buffer. Oddly enough, every 17th reading gives 4 bytes of all 0, which is incorrect. One of the options that we are studying is that the chip is not always ready when it sends a data ready signal.
So, I know that I can’t sleep in the interrupt handler, but I would like to try to introduce a delay of 10 or 20 microseconds. Right now I have a for loop that is 100,000 and then handles the interrupt. I did not see any changes, so I thought I could see if anyone had the best technique for lively waiting. Or at least the best way to figure out how many cycles I have to go through, since I'm not sure how long it will take, or if the compiler just optimizes it all.
c linux interrupt embedded spi
Maxwell Bottiger
source share