2025-07-17 7:22 AM
Hi,
I hope this is the right place to ask. I'm currently working on interfacing an SD Card with a nucleo f767. I used the DS-Bits in CR2 to set the data frame to 8 Bit (what also should be the reset value). Despite that, MOSI always sends the whole data register, which is 16 Bits. So if I use the function below to send 0xFF, the hardware will send 0x00FF. Does anybody know this issue?
2025-07-17 7:46 AM - edited 2025-07-17 7:47 AM
Write 8 bits to the register instead of 16:
*(volatile uint8_t*)&SPI3->DR = b;
Look up data packing in the Reference Manual.
2025-07-17 7:59 AM
Thank you for the quick response. I already tried this cast, but it leads into a system crash. With the following version, the cmd0 command works. Is it save to use?
void spi_send(uint8_t b) {
while (!(SPI3->SR & SPI_SR_TXE));
__asm__ volatile("strb %0, [%1]"
:
: "r"(b), "r"(&SPI3->DR)
: "memory");
while (!(SPI3->SR & SPI_SR_TXE));
}
2025-07-17 8:32 AM
Maybe this instead:
*((volatile uint8_t*)&(SPI3->DR)) = b;