STM32L053 I2C problems with LIS3DH sensor












0















I'm trying to recover the data from the LIS3DH sensor and I found this tutorial on YouTube.



In the tutorial the person uses the following to see if the sensor is ready for use:



if(HAL_I2C_IsDeviceReady(&hi2c1,SLAVEI2C_ADD,10,100)==HAL_OK)


However when I make the connections and run the program, I don't see anything.



I connected the sensor as follows:




  • Sensor -> STM32

  • SDA -> SDA/D14 (Pull up 10kOhms)

  • SCL -> SCL/D15 (Pull up 10kOhms)

  • SDO -> 3.3v

  • CS -> 3.3V

  • GND -> GND

  • Vcc -> 3.3v


The following code is the one I am using to try to know the status of my sensor.



#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();

__HAL_RCC_GPIOB_CLK_ENABLE();
MX_GPIO_Init();
__HAL_RCC_I2C1_CLK_ENABLE();
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)
{

}

}


The error I have detected is that the waiting time to communicate with the sensor is running out HAL_I2C_ERROR_TIMEOUT. I have no idea what a mistake this may be. Do you know what may be happening?



Configuration in CUBEMX










share|improve this question




















  • 2





    This question is probably more suitable for electronics.stackexchange.com ... 10kΩ is quite a large value for I2C - I'd suggest more like 2.2kΩ. Do you have access to a logic analyser or oscilloscope to check that the STM32's peripheral is actually behaving correctly? (Might also hint at using lower resistors)

    – Attie
    Feb 15 at 18:48











  • Also, have you configured the pin muxing, so that PB8 and PB9 are connected to the I2C peripheral? Look into "Alternate Functions" in the STM32's datasheet.

    – Attie
    Feb 15 at 18:49











  • Also, note that by setting SDO high, the device's I2C address is now 0x19, but I think the HAL_I2C_IsDeviceReady() function expects this to be left shifted once.

    – Attie
    Feb 15 at 19:03
















0















I'm trying to recover the data from the LIS3DH sensor and I found this tutorial on YouTube.



In the tutorial the person uses the following to see if the sensor is ready for use:



if(HAL_I2C_IsDeviceReady(&hi2c1,SLAVEI2C_ADD,10,100)==HAL_OK)


However when I make the connections and run the program, I don't see anything.



I connected the sensor as follows:




  • Sensor -> STM32

  • SDA -> SDA/D14 (Pull up 10kOhms)

  • SCL -> SCL/D15 (Pull up 10kOhms)

  • SDO -> 3.3v

  • CS -> 3.3V

  • GND -> GND

  • Vcc -> 3.3v


The following code is the one I am using to try to know the status of my sensor.



#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();

__HAL_RCC_GPIOB_CLK_ENABLE();
MX_GPIO_Init();
__HAL_RCC_I2C1_CLK_ENABLE();
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)
{

}

}


The error I have detected is that the waiting time to communicate with the sensor is running out HAL_I2C_ERROR_TIMEOUT. I have no idea what a mistake this may be. Do you know what may be happening?



Configuration in CUBEMX










share|improve this question




















  • 2





    This question is probably more suitable for electronics.stackexchange.com ... 10kΩ is quite a large value for I2C - I'd suggest more like 2.2kΩ. Do you have access to a logic analyser or oscilloscope to check that the STM32's peripheral is actually behaving correctly? (Might also hint at using lower resistors)

    – Attie
    Feb 15 at 18:48











  • Also, have you configured the pin muxing, so that PB8 and PB9 are connected to the I2C peripheral? Look into "Alternate Functions" in the STM32's datasheet.

    – Attie
    Feb 15 at 18:49











  • Also, note that by setting SDO high, the device's I2C address is now 0x19, but I think the HAL_I2C_IsDeviceReady() function expects this to be left shifted once.

    – Attie
    Feb 15 at 19:03














0












0








0








I'm trying to recover the data from the LIS3DH sensor and I found this tutorial on YouTube.



In the tutorial the person uses the following to see if the sensor is ready for use:



if(HAL_I2C_IsDeviceReady(&hi2c1,SLAVEI2C_ADD,10,100)==HAL_OK)


However when I make the connections and run the program, I don't see anything.



I connected the sensor as follows:




  • Sensor -> STM32

  • SDA -> SDA/D14 (Pull up 10kOhms)

  • SCL -> SCL/D15 (Pull up 10kOhms)

  • SDO -> 3.3v

  • CS -> 3.3V

  • GND -> GND

  • Vcc -> 3.3v


The following code is the one I am using to try to know the status of my sensor.



#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();

__HAL_RCC_GPIOB_CLK_ENABLE();
MX_GPIO_Init();
__HAL_RCC_I2C1_CLK_ENABLE();
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)
{

}

}


The error I have detected is that the waiting time to communicate with the sensor is running out HAL_I2C_ERROR_TIMEOUT. I have no idea what a mistake this may be. Do you know what may be happening?



Configuration in CUBEMX










share|improve this question
















I'm trying to recover the data from the LIS3DH sensor and I found this tutorial on YouTube.



In the tutorial the person uses the following to see if the sensor is ready for use:



if(HAL_I2C_IsDeviceReady(&hi2c1,SLAVEI2C_ADD,10,100)==HAL_OK)


However when I make the connections and run the program, I don't see anything.



I connected the sensor as follows:




  • Sensor -> STM32

  • SDA -> SDA/D14 (Pull up 10kOhms)

  • SCL -> SCL/D15 (Pull up 10kOhms)

  • SDO -> 3.3v

  • CS -> 3.3V

  • GND -> GND

  • Vcc -> 3.3v


The following code is the one I am using to try to know the status of my sensor.



#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();

__HAL_RCC_GPIOB_CLK_ENABLE();
MX_GPIO_Init();
__HAL_RCC_I2C1_CLK_ENABLE();
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)
{

}

}


The error I have detected is that the waiting time to communicate with the sensor is running out HAL_I2C_ERROR_TIMEOUT. I have no idea what a mistake this may be. Do you know what may be happening?



Configuration in CUBEMX







c embedded






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 15 at 18:54









Attie

11.9k32945




11.9k32945










asked Feb 15 at 16:20









Jose LopezJose Lopez

1




1








  • 2





    This question is probably more suitable for electronics.stackexchange.com ... 10kΩ is quite a large value for I2C - I'd suggest more like 2.2kΩ. Do you have access to a logic analyser or oscilloscope to check that the STM32's peripheral is actually behaving correctly? (Might also hint at using lower resistors)

    – Attie
    Feb 15 at 18:48











  • Also, have you configured the pin muxing, so that PB8 and PB9 are connected to the I2C peripheral? Look into "Alternate Functions" in the STM32's datasheet.

    – Attie
    Feb 15 at 18:49











  • Also, note that by setting SDO high, the device's I2C address is now 0x19, but I think the HAL_I2C_IsDeviceReady() function expects this to be left shifted once.

    – Attie
    Feb 15 at 19:03














  • 2





    This question is probably more suitable for electronics.stackexchange.com ... 10kΩ is quite a large value for I2C - I'd suggest more like 2.2kΩ. Do you have access to a logic analyser or oscilloscope to check that the STM32's peripheral is actually behaving correctly? (Might also hint at using lower resistors)

    – Attie
    Feb 15 at 18:48











  • Also, have you configured the pin muxing, so that PB8 and PB9 are connected to the I2C peripheral? Look into "Alternate Functions" in the STM32's datasheet.

    – Attie
    Feb 15 at 18:49











  • Also, note that by setting SDO high, the device's I2C address is now 0x19, but I think the HAL_I2C_IsDeviceReady() function expects this to be left shifted once.

    – Attie
    Feb 15 at 19:03








2




2





This question is probably more suitable for electronics.stackexchange.com ... 10kΩ is quite a large value for I2C - I'd suggest more like 2.2kΩ. Do you have access to a logic analyser or oscilloscope to check that the STM32's peripheral is actually behaving correctly? (Might also hint at using lower resistors)

– Attie
Feb 15 at 18:48





This question is probably more suitable for electronics.stackexchange.com ... 10kΩ is quite a large value for I2C - I'd suggest more like 2.2kΩ. Do you have access to a logic analyser or oscilloscope to check that the STM32's peripheral is actually behaving correctly? (Might also hint at using lower resistors)

– Attie
Feb 15 at 18:48













Also, have you configured the pin muxing, so that PB8 and PB9 are connected to the I2C peripheral? Look into "Alternate Functions" in the STM32's datasheet.

– Attie
Feb 15 at 18:49





Also, have you configured the pin muxing, so that PB8 and PB9 are connected to the I2C peripheral? Look into "Alternate Functions" in the STM32's datasheet.

– Attie
Feb 15 at 18:49













Also, note that by setting SDO high, the device's I2C address is now 0x19, but I think the HAL_I2C_IsDeviceReady() function expects this to be left shifted once.

– Attie
Feb 15 at 19:03





Also, note that by setting SDO high, the device's I2C address is now 0x19, but I think the HAL_I2C_IsDeviceReady() function expects this to be left shifted once.

– Attie
Feb 15 at 19:03










0






active

oldest

votes












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1406159%2fstm32l053-i2c-problems-with-lis3dh-sensor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1406159%2fstm32l053-i2c-problems-with-lis3dh-sensor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

Mangá

Eduardo VII do Reino Unido