Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hi guys, so I am trying to read the content of one of my Control Registers but every time I am reading it, without changing value, the SPI_Receive reads different value. I am looking at it with my project leader for more than 10 hours and we just can't figure it out. The sensor I am using is LSM9DS1 and the microcontroller is STM32L432KC. Here is my read function. I am trying to use Transmit and TransmitReceive, but none of them is working. The driver direction is 0x80 / 0x00 base on reading or writing. The CS_Activate and Deactivate are used to enable SPI communication. Driver.data is an uint8_t array of 12 items. The "n" parameter is count of bytes. Any ideas how to fix this?
spi_read
void spi_read(uint8_t n) { driver.data[0] = driver.direction | (driver.address & 0x3F); driver.data[1] = 0; CS_Activate(); HAL_SPI_TransmitReceive(driver.hspi, driver.data, driver.data, n + 1, 1000); CS_Deactivate(); driver.data[0] = driver.direction | (driver.address & 0x3F); uint8_t data_temp[2]; data_temp[0] = 0; data_temp[1] = 0; CS_Activate(); HAL_SPI_Transmit(driver.hspi, driver.data, n /*+ 1*/, 1000); HAL_SPI_Receive(driver.hspi, data_temp, n /*+ 1*/, 1000); CS_Deactivate(); }