cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L486: SPI-Clock doubled

Byteslave
Associate

Use SPI with MCU above.  With

spi_transmit(0x55);

and

void spi_transmit(uint8_t tx_data) { SPI1->DR= tx_data; while (!(SPI1->SR & SPI_SR_TXE)); }

I have 16 SPI clocks. Init was:

hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

 Data on MOSI showing on the first 8 clocks, MOSI on remaining 8 clocks is zero.

While using HAL (same init):

pdat= 0x55; HAL_SPI_Transmit(&hspi1, (const uint8_t *)&pdat, 1, 100);

I have, as expected, 8 SPI clocks.

Any Suggestions? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Write 8 bits to DR instead of 16.

*(volatile uint8_t*)&SPI1->DR = tx_data;
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

Write 8 bits to DR instead of 16.

*(volatile uint8_t*)&SPI1->DR = tx_data;
If you feel a post has answered your question, please click "Accept as Solution".

Wow, that worked! I'm still confused, because "tx_data" is 8bits, init was for 8bit data and the subroutine already worked at an STM32F103C8T6.  But it is like it is, Thanks again!

The access size is dictated by the left hand side of the expression and since SPI->DR is a 16-bit register, that's what you write regardless of what is on the right, which gets converted to the right size.

F103 doesn't have data packing so it works there.

If you feel a post has answered your question, please click "Accept as Solution".