2019-03-28 07:21 AM
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
2019-03-28 08:18 AM
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.
2019-04-01 03:25 AM
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?
2019-04-01 06:24 AM
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();
}
2019-04-01 06:29 AM
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
2019-04-01 07:11 AM
Read out SPI registers content, and check/compare between "working" and "non-working" state.
JW