2013-11-14 01:34 AM
Hi,
I am in trouble with 8-bit SPI communication. I did this: SPI1->CR1 = (uint16_t)( SPI_CR1_MSTR | SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_SSI | SPI_CR1_SSM ); SPI1->CR2 = (uint16_t)(SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2 SPI_CR2_FRXTH); and to send data this while (BitMaskIsClear (SPI1->SR, SPI_SR_TXE)); SPI1->DR = (uint8_t)(0x0F); while (BitMaskIsClear (SPI1->SR, SPI_SR_TXE)); SPI1->DR = (uint8_t)(0x55); while (BitMaskIsClear (SPI1->SR, SPI_SR_TXE)); SPI1->DR = (uint8_t)(0xAA); while (BitMaskIsClear (SPI1->SR, SPI_SR_TXE)); SPI1->DR = (uint8_t)(0x5A); but I get 4 times 16 Bit out with the high byte always being 0x00. How can I send only 8 bit with each access to ->DR without doing any prepacking before loading ->DR ? Also I would like to repeat this in a loop to send any number (even or odd) of bytes. I didn't try it yet but I guess there will be a similiar problem when trying to read single bytes out of ->DR while there are two bytes in it. Are there any hints on this? I read the data sheet but I feel it is a bit confusing. I am using STM32F051, GCC Thank you very much for any help Martin2013-11-14 07:52 AM
Hi,
I found out myself. To write or read only 8 bit out of the Tx / RxFifo you need to access ->DR as an 8 bit type but it is declared as a uint16_t. So you need to cast it like it is done in the lib functions SPI_SendData8 and SPI_ReceiveData8. Hope anyone can use this hint. Martin