2017-11-09 06:07 AM
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
2017-11-09 07:13 AM
Cast the SPI2->DR write to an 8-bit width?
2017-11-09 08:40 AM
unfortunately already tried
SPI2->DR = (uint8_t) dato;
also (any number 8bit)
SPI2->DR = 0x55;
2017-11-09 08:41 AM
No, like this
*((uint8_t *)&SPI2->DR) = 0x55;
2017-11-10 06:00 AM
Okay ... it seems to work.
send 8 bits.
ThankBut 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.
2017-11-10 08:37 AM
>>
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.