Skip to main content
Davide Maiocchi
Associate
November 9, 2017
Question

STM32L496 SPI don't work 8bit

  • November 9, 2017
  • 5 replies
  • 1111 views
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

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    November 9, 2017
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Davide Maiocchi
    Associate
    November 9, 2017
    Posted on November 09, 2017 at 16:40

    unfortunately already tried

    SPI2->DR = (uint8_t) dato;

    also (any number 8bit)

    SPI2->DR = 0x55;

    Tesla DeLorean
    Guru
    November 9, 2017
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..