c - STM32F4 accelerometer -


I need to read some data from accelerometer LIS3DSH in STM 32F4 Discovery. I have this main code:

  uint8_t writeData (uint8_t data) {while (SPI_I2S_GetFlagStatus (SPI1, SPI_I2S_FLAG_BSY) == SET); SPI_I2S_SendData (SPI1, data); While (SPI_I2S_GetFlagStatus (SPI1, SPI_I2S_FLAG_BSY) == SET); Return SPI_I2S_ReceiveData (SPI1); } Zero setrag (uint8_t address, uint8_t value) {GPIO_ResetBits (GPIOE, GPIO_Pin_3); WriteData (address); WriteData (value); GPIO_SetBits (GPIOE, GPIO_Pin_3); } Uint8_t getReg (uint8_t address) {uint8_t data = 0; Address = (1  7); GPIO_ResetBits (GPIOE, GPIO_Pin_3); WriteData (address); Data = write data (0x00); GPIO_SetBits (GPIOE, GPIO_Pin_3); Return data; } Int main (empty) {four letter [4]; Usart_init (); Spi_init (); // activate the accelerometer // SetRage (LIS302DL_CTRL_REG1, (1 & lt; PD_CTRL_REG1)); LIS3DSH_Init (); // Read the data from the three registers and write it in the urt while (1) {delay (); Itao (int8_t) LIS3DSH_Get_X_Out (1), and str); Send_str (& amp; str); Send_str (":"); Itao (int8_t) getReg (LIS302DL_OUT_Y), & amp; str;); Send_str (& amp; str); Send_str (":"); Itao (int8_t) getReg (LIS302DL_OUT_Z), & amp; str;); Send_str (& amp; str); Send_str ("|"); }}  

But it only gets the first value. For example:

  5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 | 5: 32: 128 |  

I use USART2 to read this data. Can someone say how to update data in real time? For example, if I change the board, will the data change?

We can start searching for this error everywhere.

  1. You are saying that you are using uart2 , but there are some things to put in spi . >
  2. You are using a library that already provides LIS3DSH_Get_Y_Out and more. So why do you useGrag ??? Just do it with X coordinates
  3. In Lib, I think spi init has been created in LIS3DSH_Init () then its own spit int from there < / Strong>.
  4. Ensure that you have an LIS 3DSH and then do not use LIS302DL_OUT_Z macros. New searches have used LIS302DL . If you have an LIS 302 DL, I can assure that it does one thing.

Solution: Try to use and exit and set reg code and your other spi_init.

Something like this:

Include # LIS3DSH.h int main (zero) {char str [4]; Usart_init (); LIS3DSH_Init (); While (1) {delay (); Itao (int8_t) LIS3DSH_Get_X_Out (1), and str); Send_str (& amp; str); Send_str (":"); Itao (int8_t) LIS3DSH_Get_Y_Out (1), & str;); Send_str (& amp; str); Send_str (":"); Itao (int8_t) LIS3DSH_Get_Z_Out (1), and str); Send_str (& amp; str); Send_str ("|"); }}

Comments