Question
STM32F417 and LIS3DH SPI1 problem
Posted on February 13, 2014 at 22:59
Hi forum!
Here is a very strange problem I'm facing with the SPI1 peripheral of the STM32F417 connected to the LIS3DH. I have to single-step through my code with my debugger in order to get the right data from the LIS3DH, otherwise I end up getting just 0xFF.Here is my setup:- PA4 set to OUT and Pull_UP used as CS♯ for LIS3DH, toggled by me through software.- PA5/6/7 set to AF and PP.- All pins at 50MHz, portA clock is enabled, SPI1 clock is enabled.How I read a byte from the STM LIS3DH:ACCEL_SELECT();SPI1->DR = (uint8_t)(0x80 | reg); // set bit 7 to readwhile( !(SPI1->SR & SPI_I2S_FLAG_TXE) );SPI1->DR = 0x00; // dummy bytewhile( !(SPI1->SR & SPI_I2S_FLAG_TXE) );while( SPI1->SR & SPI_I2S_FLAG_BSY );*data = (uint8_t)(SPI1->DR & 0xFF);ACCEL_DESELECT();Open to suggestions! Thanks! #lis3dh #stm32f417