2025-04-12 1:16 PM
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!
Solved! Go to Solution.
2025-04-12 5:12 PM
Write 8 bits to DR instead of 16.
*(volatile uint8_t*)&SPI1->DR = tx_data;
2025-04-12 5:12 PM
Write 8 bits to DR instead of 16.
*(volatile uint8_t*)&SPI1->DR = tx_data;
2025-04-13 1:02 AM
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!
2025-04-13 6:45 AM
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.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.