BME280 gives wrong values after Ethernet begin with W5500

Post here all questions related to STM32 core if you can't find a relevant section!
adrian_123
Posts: 8
Joined: Thu Jul 01, 2021 12:54 pm
Answers: 1

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by adrian_123 »

Hi there, Ive introduced the piece of code and I gave 5 wanted layers through serial. One time before the Ethernet.begin() and one after. This is the result:
Captura de pantalla 2021-07-04 a las 11.03.04.png
Captura de pantalla 2021-07-04 a las 11.03.04.png (54.74 KiB) Viewed 3695 times
Does it give you a hint?
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by mrburnette »

adrian_123 wrote: Sun Jul 04, 2021 9:03 am ...
Does it give you a hint?
Re-reading you intro post, you indicated you are using cores:
My core is the one from stm32duino. JSONs included in Arduino:
https://github.com/stm32duino/BoardMana ... index.json
http://dan.drown.org/stm32duino/package ... index.json
Which core are you using during compile/link? The github core is the STM32 corporate core and the second core listed from Dan is a personal core used by some members; but not a globally recommended core for all.

There is nothing obvious in the memory printout (IMO) other than there does not seem to be a substantial amount of memory being consumed by the Ethernet call to initialize ... thus, the stack numbers look nominal. I would expect, however, that as webpages are being built, the string assignments will consume memory unless the webpage is static except for displayed variables. This situation is best handled IMO by websockets/AJAX.

There also may be a conflict in the two libraries with variables naming or allocations. A conflicting variable name or scope issue could be disastrous.

May I suggest you eliminate the Dan Drown core. If you wish to investigate using Steve's core or Roger's core, there may be some benefits afforded; but the forum standard for recommendations is the STM32 Official Core.

Ray
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by ag123 »

noticed something, initially you entered 5 layers of stack, it is 15556 bytes of free memory. the next time you run 5 layers again it is 15436.
well that isn't 'a lot' but does it become lesser and lesser if you run it n times? that could hint on a *memory leak*, very rare on a stm32f103 to find this. or more correctly 'no one' knows it happens ;/
that Freestack() thing is useful to insert deep in codes to 'check for free memory', i.e. call it once in a while deep in the codes, including in the libraries.
note that normally when things go back to loop() the stack is unwound and hence you have more 'free' memory, this also doesn't tell you if during the library calls, it go deep down, use up all that memory, overwrite some global variables then unwind everything and tells you have 15k 'free' memory, and that global variable(s) is smashed. oh well, these are supposed to be 'microcontrollers' after all, we are using them like that 8GB raspberry pi 4 these days :lol:
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by mrburnette »

Hardly anything to laugh about, :lol:
but, why not? Just because we work with computers does NOT mean that every action is cast in stone:
https://stackoverflow.com/questions/239 ... d-behavior
Other examples of undefined behavior include accessing an array beyond its bounds, dereferencing the null pointer, accessing objects after their lifetime ended or writing allegedly clever expressions like i++ + ++i.

Section 1.9 of the C++ standard also mentions undefined behavior's two less dangerous brothers, unspecified behavior and implementation-defined behavior:
I doubt there is a memory leak, likely the function call to start the Ethernet initializes some local variables within the function. After all, he polled the stack, made a call, and polled the stack ... clearly, the function call

Code: Select all

Ethernet.begin(mac)
is NOT located within loop().

Just for sanity, within loop() you can increment a counter, take a mod, do a conditional check for 0, and do the free memory inspection every 100 or 500 or 1000 times through the loop...
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by ag123 »

a thing about ethernet i'd think is that tcp/ip gets involved. hence, things may be a little more complicated than just straight forward ethernet.
tcp itself needs to keep state, keep the packet sequences, fragment sequences etc. that can easily blow the budget of that 20k sram with a simple ip or tcp fragmentation attack
https://www.imperva.com/learn/ddos/ip-f ... -teardrop/
nevertheless these are speculations, debugging that would take some effort
adrian_123
Posts: 8
Joined: Thu Jul 01, 2021 12:54 pm
Answers: 1

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by adrian_123 »

Both display and sensor dont work when I do ethernet.begin(). The display does not print anything else and the bme sends the same wrong values such as -146ºC.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by mrburnette »

#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
You "could try the OLED" using SPI, The Adafruit lib supports both I2C and SPI ... just be careful with CS.

The W5500 ethernet module is SPI. I did not look into https://github.com/arduino-libraries/Ethernet to see how CS is implemented. There are more W5500 libraries, so it "may" be prudent to try another library.
The display does not print anything else and the bme sends the same wrong values such as -146ºC.
If you just print over serial (do not instantiate the OLED), does the BME280 function correctly? That is, can BME280, Ethernet, and MQTT all coexist and function?

The big draw to Arduino is the vast 3rd party libraries; IMO, that is also the great frustration. When things do not work as intended, diagnosis is a major problem. In "more" professional environments, the debug facilities allow tracing, variable viewing, and breakpoints ... all very powerful magic.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by fpiSTM »

My 2 cents is that it can be related to endianness management done by the lib. I've saw this kind of issue with UIPEthernet lib.
adrian_123
Posts: 8
Joined: Thu Jul 01, 2021 12:54 pm
Answers: 1

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by adrian_123 »

They cannot work all at once if I dont initialize the display the sensor still does not work and the other way around has the same result. I also tried to do the bme.begin and the display.behin after the ethenet begin but it crashes. Generaly, ethernet sends values but the ones coming from the sensor are wrong and the display does not obey me. I dont think its a problem of power but maybe some collisions between libraries or so...
adrian_123
Posts: 8
Joined: Thu Jul 01, 2021 12:54 pm
Answers: 1

Re: BME280 gives wrong values after Ethernet begin with W5500

Post by adrian_123 »

Hi there,
I got the problem. Theres no problem with the stm32 going out of resources, thres no problem of power nor problems with library collisions. I had a defective via in my pcb. STM32 is suitable to work with a ethernet w5500 module, and a display and a bme280 at the same i2c bus. Thanks for all the replies and concerns.
Post Reply

Return to “General discussion”