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?
I2C problem with BH1750
I2C problem with BH1750
- Attachments
-
- i2cdev_OK.zip
- (4.12 KiB) Downloaded 14 times
-
- i2cdev_NO_OK.zip
- (7.93 KiB) Downloaded 14 times
-
MicroController
- Posts: 2704
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: I2C problem with BH1750
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().
Try using i2c_master_transmit_receive() instead of i2c_master_transmit() + i2c_master_receive() in i2c_dev_read_reg().
Re: I2C problem with BH1750
Atteched sample projecdt with problem
- Attachments
-
- BH1750_Prj.zip
- (43.4 KiB) Downloaded 16 times
Re: I2C problem with BH1750
@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).
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).
Who is online
Users browsing this forum: Baidu [Spider], Semrush [Bot] and 3 guests