2019-02-13 01:59 PM
Hi,
I'm trying to recover the data from the LIS3DH sensor and I found this tutorial " https://www.youtube.com/watch?v=A1CIOUZdeR4". In the tutorial the person uses function " if(HAL_I2C_IsDeviceReady(&hi2c1,SLAVEI2C_ADD,10,100)==HAL_OK) " to see if the sensor is ready for use. However when I make the connections and run the program, I don'tsee anything, I do not know if you can give me some advice.
I connected the sensor as follows:
Sensor STM32
SDA -> SDA/D14
SCL -> SCL/D15
SDO -> 3.3v
GND -> GND
Vcc -> 3.3v
#include "main.h"
I2C_HandleTypeDef hi2c1;
#define SLAVEI2C_ADD 0x19
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_I2C1_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_I2C1_Init();
HAL_Delay(1000);
if(HAL_I2C_IsDeviceReady(&hi2c1,SLAVEI2C_ADD,10,100)==HAL_OK)
{
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
}
while (1)
{
}
}
I want to recover the aceleration but i can't do a simple step..... Someone could help me???
2019-02-14 01:58 AM
well all the I2C pins are in PORTB so use the port B pins, go to page number 46 of datasheet for Alternate functions of portB.
2019-02-14 02:00 AM
My apologies ! I guess I misjudged. you have selected right pins
2019-02-14 02:04 AM
__HAL_RCC_GPIOB_CLK_ENABLE();
mx_gpio_init();
__HAL_RCC_I2C1_CLK_ENABLE();
mx_i2c1_init();
have you enabled the clocks already? as above
2019-02-14 02:42 PM
No, i didn't enable. I will try it!!!
2019-02-15 03:20 AM
I've tried, but the LED never lights up, as if the sensor was never ready.
2019-02-15 03:40 AM
did you enable the clock for the port A on which LED resides. If it doesn't work kindly show the GPIO and I2C initialisation functions. Also just in case I hope you have externally pulled up the SDA and SCL of LIS3DH using 10k resistors and connected CS also to VCC.
2019-02-15 05:44 AM
I enabled the pullup option of the STM32 card, also I have set CS to Vcc, I am checking carefully what happens when using HAL_I2C_IsDeviceReady. And I have found that I can't establish a connection in the defined time and therefore is in a HAL_Error state.
2019-02-15 06:26 AM
All GPIO pins have weak internal Pullup and pulldown resistors. So the external is needed. Also as you say that there is timing issue kindly synchronise the frequency while initiating the i2c at i2c.init.timing.
2019-02-17 09:23 AM
Hi,
Thanks for all your answers, i solved my problem.