Sending one byte via SPI STM32G474
I need to send data one byte at a time via SPI. After transferring the byte, I set "Chip Select" from the program to state 1. I track the end of the transfer by the BSY bit in the SPI_SR register. But the microcontroller transmits two bytes, the first byte is the value from the DR register and the second byte 0. The transmission length is set to 8 bits. I tried to set a different transmission length, but the microcontroller always sends two transmissions of the length I set. Below is the initialization code.
RCC-> APB2ENR | = RCC_APB2ENR_SPI4EN;
// CPHA = 1 // CPOL = 1
SPI4-> CR1 =
SPI_CR1_BR_1 | SPI_CR1_BR_2 | SPI_CR1_BR_0 | // Baud rate = Fpclk / 256
SPI_CR1_MSTR |
SPI_CR1_CPOL |
SPI_CR1_CPHA |
SPI_CR1_SSM |
SPI_CR1_SSI;
SPI4-> CR2 = SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2;
SPI4-> CR1 | = SPI_CR1_SPE;
Send data
LCD_CS_Clr();
_delay_us(2);
SPI4->DR = data;
while((SPI4->SR & SPI_SR_BSY) != 0);
_delay_us(2);
LCD_CS_Set();
_delay_us(2);
