Page 1 of 1

I2C problem with BH1750

Posted: Wed Jun 18, 2025 9:58 am
by edo76mal
Hi.

I'm developing, with wroom32, a simple weather station.
I'm using esp-idf 5.4.2

I find that using i2c.c [with attached i2cdev_OK] everything works, while using i2c_master.c [with attached i2cdev_NO_OK] trasmission fails. In particular I find this:

Found BH1750 device at 0x23
[0;31mE (649) i2c.master: I2C transaction unexpected nack detected[0m
[0;31mE (649) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed[0m
[0;31mE (652) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed[0m

It seems a problem of i2c_master.

Can you help me?

Re: I2C problem with BH1750

Posted: Wed Jun 18, 2025 12:27 pm
by MicroController
The BH1750 seems to expect a NACK from the master at the end of a read transaction. The master not sending the NACK at the end may 'confuse' the slave and cause it to respond with a NACK to the next write transaction.

Try using i2c_master_transmit_receive() instead of i2c_master_transmit() + i2c_master_receive() in i2c_dev_read_reg().

Re: I2C problem with BH1750

Posted: Wed Jun 18, 2025 1:31 pm
by edo76mal
@MicroController

It doesn't work.

Re: I2C problem with BH1750

Posted: Wed Jun 18, 2025 4:05 pm
by edo76mal
Atteched sample projecdt with problem

Re: I2C problem with BH1750

Posted: Mon Jul 21, 2025 11:19 am
by eriksl
@microcontroller: either method (read or write+repeatedstart+read) will work, both will stop data reception with a NAK. So that's not the problem.

I have it working, so it should be possible.

The bh1750 is a very simple I2C device. It accepts either a write with a "register pointer" or a read (no register pointer). So a write-repeatedstart-read cycle doesn't make sense. IIRC the register pointer can be set independent of the value (i.e. in 2 transactions).