News:

Let's find out together what makes a PIC Tick!

Main Menu

Hardware SPI in 16-bit devices?

Started by trastikata, Jul 26, 2024, 07:16 PM

Previous topic - Next topic

trastikata

Hello,

I've observed an interesting find, in 16-bit devices one has to read the SPI buffer after each transmission frame, otherwise this will cause RXBUF overflow and the SPI module will not transmit further.

Thus after each byte has been sent, the firmware has to read back the buffer to keep it from overflowing. This overhead actually almost doubles the clock cycles?

In my test using 1:1 prescallers and SPI interrupt for the SPI clock, I actually measure longer total times than simple bit-banging. However this is not the case in 8-bit devices.

Am I missing something here?

top204

Reading the buffer after sending is fairly standard on all devices, otherwise, the buffer will overflow and nothing will be received or transmitted. You can empty the buffer by clearing a flag, but I usually read the buffer after sending, regardless whether it is used or not, and clear the flag before sending, just to make sure.

Make sure you are sending 8-bits and not 16-bits or 32-bits. Sending 16-bits on a 16-bit device is, I think, its default. So it will take slightly longer to send, and most also send 32-bits.

trastikata

What you suggest Les is much better than what I was doing with the hardware interrupt, saves a lot of cycles when multiple bytes are transferred, thanks.