Question
STM32F051 SPI1 Strange behaviour
Posted on November 02, 2015 at 22:52
My problem is that i am not able to write to SPI1->DR. I have a LIS2DH accelerometer on SPI1 and i am able to read �Who_Am_I'' register and it returns correct value. However when i try to read any other register value, i always read 0xFF. I noticed, that whatever i am trying to write to SPI1->DR register, result is always 0xFF in DR. Simple code writing to SPI1->DR :
if ((SPI1->SR & SPI_SR_TXE) == SPI_SR_TXE) /* Test Tx empty */{/* Will inititiate 8-bit transmission if TXE */*(uint8_t *)&(SPI1->DR) = 0x20;}After this line of code goes through, i am seeing 0xFF in SPI1->DR. Does anyone can help me to solve this out??My SPI Configuration: (Yes, clock is enabled elsewhere.)void spi1_config(void){SPI_I2S_DeInit(SPI1); // DeInit SPI to the reset state./* Configure SPI driver */spi1_struct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // Use full duplex (receive and transmit)spi1_struct.SPI_Mode = SPI_Mode_Master; // MCU is a masterspi1_struct.SPI_DataSize = SPI_DataSize_8b; // Use 8 bit size dataspi1_struct.SPI_CPOL = SPI_CPOL_High;spi1_struct.SPI_CPHA = SPI_CPHA_2Edge;spi1_struct.SPI_NSS = SPI_NSS_Soft; // Control Chip select pin (CS) from softwarespi1_struct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; // SPI Clock Pscspi1_struct.SPI_FirstBit = SPI_FirstBit_MSB; // First bit send is MSB (required by LIS2DH)spi1_struct.SPI_CRCPolynomial = 7; // Not Relevant parameter/* Initialize SPI1 peripheral */SPI_Init(SPI1, &spi1_struct);/* Enable SPI1 peripheral */SPI_Cmd(SPI1, ENABLE);} #spi1 #problem #stm32f051