cbalint13 / tinnymodbus

RS485 ModBus tiny multi-sensor module
Other
102 stars 31 forks source link

BME280 with 9600Baud #31

Closed no-ahnu closed 8 months ago

no-ahnu commented 8 months ago

Hello cbalint13, As written here I activated the internal divider to enable the baud rate 9600. Unfortunately my BME280 no longer has any humidity. Do you have an idea as to what this could be? The humidity works with the baud rate of 38400 and without the clock divider.

I have already activated softi2c's slow mode and I2C_NOINTERRUPT. Unfortunately, no humidity can be elicited from the BME.

Thanks for your help and tips.

no-ahnu commented 8 months ago

I looked at softi2c.c again and tried to understand. From line 131 LINK a counter is set. I recalculated it: image

By default no mode is set (Fast or Slow). Then (with F_CPU=1MHz) a negative value comes out. I have activated slow mode. Values from the BME280 are output, but not plausible. Therefore I adjusted the formula.

#define I2C_DELAY_COUNTER (((I2C_CPUFREQ*8/23500L)/2-18)/3)

This means the BME280 works at 1Mhz and 9600Baud.

@cbalint13 should that be included in the program code?

#if I2C_FASTMODE
#define I2C_DELAY_COUNTER (((I2C_CPUFREQ/350000L)/2-18)/3)
#else
#if I2C_SLOWMODE
#if I2C_CPUFREQ == 1000000
#define I2C_DELAY_COUNTER (((I2C_CPUFREQ*8/23500L)/2-18)/3)
#else
#define I2C_DELAY_COUNTER (((I2C_CPUFREQ/23500L)/2-18)/3)
#endif
#else
#if I2C_CPUFREQ == 1000000
#define I2C_DELAY_COUNTER (((I2C_CPUFREQ*8/90000L)/2-18)/3)
#else
#define I2C_DELAY_COUNTER (((I2C_CPUFREQ/90000L)/2-18)/3)
#endif
#endif
#endif