cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L496 SPI don't work 8bit

Davide Maiocchi
Associate II
Posted on November 09, 2017 at 15:07

Hi,

i use a STM32L496.

I configured the SPI to communicate 8bit but it always generates 16clk e 16bit data.

SPI : MASTER- halfduplex 2wire(1clk , 1Mosi/Miso)

 /* Enable clock for SPI2 */

 RCC->APB1ENR1 |= RCC_APB1ENR1_SPI2EN;

 // BIDIMODE=1 - BIDIOE=1 - RXONLY=0 - SSM=1 - SSI=1 - LSBFIRST=0 - BRR=111 - MSTR=1 - CPOL=0 - CPHA=0

 SPI2->CR1 = SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_BR | SPI_CR1_MSTR;

 //FRXTH=1 - DS=0111 8bit - RXNEIE=1

 SPI2->CR2 = SPI_CR2_FRXTH | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0 | SPI_CR2_RXNEIE;

'CR2 DS' it does not work

5 REPLIES 5
Posted on November 09, 2017 at 16:13

Cast the SPI2->DR write to an 8-bit width?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 09, 2017 at 16:40

unfortunately already tried

SPI2->DR = (uint8_t) dato;

also (any number 8bit)

SPI2->DR = 0x55;

Posted on November 09, 2017 at 16:41

No, like this

*((uint8_t *)&SPI2->DR) = 0x55;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 10, 2017 at 14:00

Okay ... it seems to work.

send 8 bits.

Thank 

But it's a workaround.

I ask, but the settings of the (SPI2->CR2 DS port [2.0] )are not useful.

I also tried the STM32CubeMX, same settings as mine, it does not work. 

Posted on November 10, 2017 at 16:37

>>

But it's a workaround.

Not really the structure definition is for a 16-bit register, the peripheral hardware sees the width of the write operation, it recognizes your write to DR as two bytes. Create a structure with an unnamed union if you don't want to see how the sausage is made.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..