cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-G071 + STM32CubeIDE has I2C working for one project but not others

Seth Kaz
Associate

I have a situation where I'm starting to work with the STM32CubeIDE and STM32 MCUs, and I've followed some tutorials with relatively positive success. However, I ran into an issue where I got I2C working on one project, but I cannot for the life of me get it working for any other projects.

Details:

STM32CubeIDE v 1.6.0 running on up-to-date Win10.

My target is a Nucleo-G071RB board with a PCT2075 I2C temperature sensor attached.

I'm following Shawn Hymel's tutorials at https://www.digikey.com/en/maker/projects/getting-started-with-stm32-i2c-example/ba8c2bfef2024654b5dd10012425fa23 .

All the background:

I followed along the tutorial, and was able to get a project working once. I continued on, making other projects and got other facets of the project working (FreeRTOS, GPIO, Timers, etc). When I went to integrate all those features, I found myself in a situation where the I2C stopped working and would raise an error ending up in the error handler. I tried changing lots of different things to get it to work. I even tried making a new project in a new workspace, but nothing seemed to fix the problem.

Thankfully, I kept that original project, and it continues to work. As in, I can change projects and/or workspaces back and forth, and with that one original demo project, it works, but with every other project/workspace, it fails.

I've verified that the I2C comms happens using a Saleae (both digital and analog channels). When it works, the comms happen (both write and read). When it doesn't work, neither the SDA nor SCL lines toggle. There looks to be a little extra noise at the same overall period (500ms) of the comms, but I'm not sure if that's anything.

Does anyone have any recommendations I can try to fix this?

EDIT: I've also tried copying all the code from the main.c file over from the working project to the non-working projects, and that doesn't fix it. I tried copying all the project files over, that does get it to work, but I would rather figure out what's wrong here so it doesn't burn me later.

EDIT: Also, I'm doing the setup of the peripherals through the MX view within STM32CubeIDE. I'm also making sure to not add code outside of the user code begin/end blocks.

2 REPLIES 2
KnarfB
Principal III

> PCT2075 I2C temperature sensor attached.

Do you have pull-ups on the I2C bus? How is the sensor powered?

> ending up in the error handler

Try to find out how that came. Who called it and why? Debug-Step through the project and try to understand what happend before.

You may also compare the I2C registers (SFR Register view). Differences in clock speed, I2C timing register and/or GPIO pin setup may also be relavant.

hth

KnarfB

Seth Kaz
Associate

>Do you have pull-ups on the I2C bus? How is the sensor powered?

So the PCT2075 is sitting on an Adafruit board. I've connected it to the 3.3V+GND rails from the Nucleo board using a QWIIC to 0.1" cable adapter. The breakout board has 10k pull ups on the I2C bus.

>Try to find out how that came. Who called it and why? Debug-Step through the project and try to understand what happend before.

When I do the step through, it is the HAL_I2C_Master_Transmit that's returning the HAL_ERROR value.

HAL_I2C_Master_Transmit > I2C_WaitOnTXISFlag_UntilTimeout > I2C_IsAcknoledgeFailed is where it fails returns the HAL_ERROR.

Thanks for the fast response. I'll poke around the SFR Register view and get back to you. I did already do a line by line comparison of the generated Init functions, and they are the same for both pieces of code.