cancel
Showing results for 
Search instead for 
Did you mean: 

8bit data transfer on a SPI's 32bit DR register

A Maq
Senior

Using STM32F767 Nucleo board and STMCubeIDE I am trying to transmit SPI data with data size of 8bit per transaction while I have setup my SPI2 in Full Duplex mode.

Problem is that although I am able to transmit from MCU and receive on slave side the data whatever I am trying to send that is "Hello World" message for a test. But with each byte I get one random data byte then the right data byte again as shown in attached screen shot decoded on Logic Analyzer.

As I am trying to send 8 bit data while SPI_DR (data register ) is mapped as 32bit in register structure for SPI while only 16bit is used based on datasheet.

It seems like that is the problem 8bit data is going ok but rest of the register gets transmitted too that has unknown values .

What would be the best solution to force the 8bit data transfer on a 32bit register using C language?

Following are my current configuration settings

SPI_Handle_t SPI2Handle;

SPI2Handle.Spix = SPI2; // SPI2 peripheral

SPI2Handle.SPIConfig.SPI_Bus_Config = SPI_BUS_CONFIG_FULLDUP; // Full Duplex Mode

SPI2Handle.SPIConfig.SPI_Device_Mode = SPI_DEVICE_MODE_MASTER ; // Master

SPI2Handle.SPIConfig.SPI_ClckSpeed = SPI_SCLK_SPEED_DIV2 ;// Full Speed

SPI2Handle.SPIConfig.SPI_DFF = SPI_DFF_8BITS; // Data size is 8bits

SPI2Handle.SPIConfig.SPI_CPOL = SPI_CPOL_LOW;

SPI2Handle.SPIConfig.SPI_CPHA = SPI_CPHA_LOW;

SPI2Handle.SPIConfig.SPI_SSM = SPI_SSM_EN; // Software slave management enabled

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

If you write using a 8-bit wide store instruction, only one byte will be sent. This can be accomplished by casting like

*(__IO uint8_t*)(&SPI2->DR) = 42;

View solution in original post

2 REPLIES 2
KnarfB
Principal III

If you write using a 8-bit wide store instruction, only one byte will be sent. This can be accomplished by casting like

*(__IO uint8_t*)(&SPI2->DR) = 42;

A Maq
Senior

Thanks very much KnarfB that resolved problem.