Skip to main content
Pramod singh
Associate II
Jan 7, 2019 9:04 AM UTC
Question

Is it a good idea to continuously reconfigure SPI form 8 bit to 16 bit or vice versa since the situation demands it.

I have two peripheral where one works on 8-bit mode and the other on 16-bit mode. 

What could be the best possible solution for such situations?

This topic has been closed for replies.

5 replies

S.Ma
Principal
Jan 7, 2019 9:12 AM UTC

I assume 2 peripheral means 2 SPI slave devices controlled by SPI Master MCU?

Use 8 bit mode to get something simple and robustly working first.

If your SPI has built-in FIFO, the difference between 8 and 16 bit transmission will be diminished.

(example on STM32L4 family).

Otherwise, reconfiguring for each addressed device is also possible, while adding complexity increases risks for bugs.

Pramod singh
Associate II
Jan 7, 2019 9:23 AM UTC

Thank you for your reply.

So basically you mean to say that, I will configure my master in 16 bit mode and use it for both the 8 and 16 bit slave if my controller supports FIFO.

However the controller i'm using is stm32f4 series

S.Ma
Principal
Jan 7, 2019 9:39 AM UTC

if SPI doesn't have FIFO, better stay in 8 bit mode for both to get started.

Unless transmitting big amount of data, or having a low SYSCLK, it should be good enough before "optimizing" such as dynamically adjusting the 8 or 16 bit mode.

Pramod singh
Associate II
Jan 7, 2019 9:48 AM UTC

by the way my controller have FIFO, I just checked it out. So what do you suggest now to do

S.Ma
Principal
Jan 8, 2019 8:26 PM UTC

if you program the SPI in 8 bit mode, a 32 bit FIFO lies between the DR and the shift register.

It means if you do a 8 bit write to DR, the fifo will store 8 bit to be "digested" into the shift register.

If you do a 16 bit DR write, it will be decomposed and queued by the FIFO as 2x8 bit to feed the shift register. you could write 3 bytes or 4 bytes at once if you'd like. With FIFO, there wouldn't be much benefits to configure the SPI in true 16 bit mode here.