cancel
Showing results for 
Search instead for 
Did you mean: 

Sending 9 bit data using SPI STM32F7

PBU
Associate III

Hi

I'm using STM32F7 series microcontroller. Is it possible to send 9 bit data using SPI? the reason is i have to send 8 bit data along with command bit (ie 9th bit). I have seen some option in datasheet like we can chose the data length between 4 bits to 16 bits in SPI control register 2 (SPIx_CR2) register.

Thanks

5 REPLIES 5

Yes, it is possible. You can choose the data length by changing the DS[3:0] bits of the SPIx_CR2 register, use binary 1000 for 9-bit data length. Read the reference manual.

Hi @After Forever​ 

Right now i'm using HAL Library. I have chosen SPI data size to 9 bits. While sending data through SPI, only the first time 9bit gets clocked out, After that 8 bits are clocked out. Do we need to change any other register settings?

So why didn't you mention that you are using HAL in your first post or least in the tags? :)

I don't use HAL, but seeing its source code, you can set the data length using the DataSize parameter before calling HAL_SPI_Init:

SPI_HandleTypeDef SpiHandle;
...
...
SpiHandle.Init.DataSize = SPI_DATASIZE_9BIT;
...
...
if (HAL_SPI_Init(&SpiHandle) != HAL_OK) {
    Error_Handler();
}

PBU
Associate III

Yeah its my Mistake =). Thanks for the Reply

Actually i did the same configuration what you have mentioned. The Issue is i have to send series of register value. Every time i have to send 9 bit value, While sending first value 9 bits were clocked out after that only 8 bits were clocked out.

Thanks

Read out SPI registers content, and check/compare between "working" and "non-working" state.

JW