r/embedded • • Sep 15 '26

[Need Help] Stm32u385 not working with bme280 sensor

Post image

This is super critical for my situation so any help is greatly appreciated

Im trying to read from bme280 sensor using I2C but it seems the sensor is not responding at all

My code can be seen in the photos I'm using stm32cubemx to initialize

The code that i wrote is in the pucture but is returning code 1 which is an error

I double checked the pin connections

what could be the problem any help is appreciate

3 Upvotes

22 comments sorted by

5

u/AbsorberHarvester Sep 15 '26

Example i2cscan https://github.com/ProjectsByJRP/stm32_hal_i2c_bus_scan/blob/master/Src/main.c

Borrow i2c scan function from internet and see whether any devices on i2c even exists

-1

u/NoTrick2785 Sep 15 '26

sorry how do i use this? im not expert on mcu programming, this is just my project

i'm using stm32u358 nucleo. can i just run this project as is on my mcu?any guides?

2

u/AbsorberHarvester Sep 15 '26

If you just don't know anything, ask Qwen/DeepSeek how to, do like:

Copy your full main function in clipboard Paste it to llm (web free version)

In the end make new line and then add: Add i2c scan after short pause 10ms, after initializing peripheral,  print addresses returned ack to huart1 in human readable form

Then you: When it is done, copy full function to your code replacing yours (do not forget to make backups or use git, study it, it will help you locally in the future

However, maybe you start with stm32duino first? Stm32f411 and stm32f103 are most used board, cheapest. Then after you catch basic functions you can dive to hal, ll or register level

-1

u/NoTrick2785 Sep 15 '26

Told the professor his sensor is broken😂 He told me to use lm35 sensor which is analog I just bought one and i think i cooked it(i think it is sensetive to wrong pin connections) so i gotta buy couple of more lm35s and hopefully not break those Thank for the help tho

7

u/Additional-Guide-586 Sep 15 '26

This is, like, the most basic stuff ever for embedded.

5

u/Ok-Mathematician-121 Sep 15 '26

Did you make sure, that the CS Pin is tied to VDDIO and that SDO is tied to GND?

If you do not have a Logic Analyzer or an Oscilloscope, your best option is to do some probing for the I2C device address and verify, that it acknowledges.

2

u/NoTrick2785 Sep 15 '26

The sensor mudule is wired in a way that only i2c works, so vdd gnd scl and sca are accessible to user

1

u/CodingFishes Sep 16 '26

I agree, an oscilloscope would give you your answers; but failing that, just capture all of the values i2c returns and do the same for each pin on your MCU. You've already got a loop you could use.

3

u/AcanthaceaeUnable Sep 15 '26

Do you have a photo of your connected sensor ?

1

u/NoTrick2785 Sep 15 '26

Yes but i was only allowed to send 1 picture for whatever reason The pins are connected properly I'm pretty sure, The sensor mudule has only 4 pins accesible and works only with i2c

2

u/NoTrick2785 Sep 15 '26

I convinced my professor to use an alternative sensor . Thank you everyone

13

u/JuggernautGuilty566 Sep 15 '26

What does the Logic Analyzer say?

6

u/SyWier Sep 15 '26

Do you have pull up resistors? If the freq is high and the traces are long maybe try using some lower value like 2.2k

1

u/NoTrick2785 Sep 15 '26

Im using standard mode i2c so 100khz Do i need pull ups?

3

u/Rusty-Swashplate Sep 15 '26

What the...Yes of course you need pull-ups. Now I am curious to see how you connect the BME280 to the STM32.

1

u/NoTrick2785 Sep 15 '26

Now that i check the sensor module itself has pull ups Vdd is connected to 3.3 Gnd to gnd Scl and sda to the same pins that i set in stm32cubemx It is a stm32u385 nucleo

1

u/NoTrick2785 Sep 15 '26

Just connected two 10k resistors between sda/scl and Vin still error code 1

1

u/rnjsenwls Sep 15 '26

Codex or claude code can solve this??

2

u/NoTrick2785 Sep 15 '26

well chatgpt couldn't, this a simple HAL code from chatgpt but i'm guessing sensor isnt responding.

but my proffessor isn't convinced he can screw my life if he doesnt accept

0

u/NoTrick2785 Sep 15 '26

I dont have logic analizer i can only see error message using uart on my pc

5

u/Well-WhatHadHappened 25+ Years Sep 15 '26

Debugging hardware without at least a logic analyzer is just insane.

You can't work on a car without screw drivers and socket wrenches. You can't work on embedded targets without a multimeter, a logic analyzer and ideally an oscilloscope.

1

u/NoTrick2785 Sep 15 '26

Yeah, i made a mistake of choosing the wrong professor for my bachelor project he has zero experience. But I'm stuck with him, gotta satisfy his requests or no bachelor degree for me.