Closed k-korn closed 6 years ago
I suspect some timing issues while reading from the slave during/after ADC.
According to the datasheet it is also possible to read from the config register. Thus, could try to write to the config register value x and read it back? And repeat this with a value y? If you get different values back, i.e. x and y then the basic i2c communication is fine and we have to look deeper at the ADC part.
Thanks, have tried reading back the config register now. Results are positive with Wire library: value written can be immediately read back with no issues.
With bgzo_i2c, however, value received back after writing does not match the one I've attempted to write. Moreover, in the following sequence:
I am actually receiving back value X, which has been written previously with Wire example.
So I assume, brzo_i2c can read data. But it's having issues writing 2-byte config register.
I had a closer look at the datasheet. Figure 17 shows the expected i2c communication:
In other words:
i. START ii. Slave Address iii. Send Pointer Register (1 Byte) iv. Send Data (here in the example 2 Bytes) v. STOP
However, what you are sending is:
In your code brzo_i2c_write(buffer,1, true);
corresponds to 1., 2., 3. then brzo_i2c_write(buffer,2,false);
corresponds to 4., 5., 6., 7.
Note that the wire library behaves differently, see the wiki.
That's why the wire library code works.
So, what you need to do is:
brzo_i2c_write(buffer,3,false);
Thanks a lot, the following actually works:
uint8_t buffer[3];
brzo_i2c_start_transaction(ADS1X15_ADDRESS, BRZO_I2C_SPEED);
buffer[0] = 1;
buffer[1] = (uint8_t)(cfg_value >> 8);
buffer[2] = (uint8_t)(cfg_value & 0xFF);
brzo_i2c_write(buffer,3,false);
rc = brzo_i2c_end_transaction();
You are welcome. I've updated the wiki on how to migrate from Wire Library to brzo, I hope it is better explained now.
Hi, I'm trying to re-implement TI ADS1015 ADC interface using brzo_i2c library, since Adafruit's implementation using Wire.h is not fast enough to read data at the rate ADS1015 cat produce.
On the same hardware (esp-12F, 4.7k pull-up resistors, ADS1015 test board), the following code in Wire.h works:
And the following code in brzo_i2c does not:
Wire-based code correctly returns different ADC values, depending on what the signal is.
brzo-i2c based code executes correctly (rc is always 0), but data coming from the device is always the same.
Hardware is OK, clock frequency of 100kHz is low enough (Wire-based example runs good at up to 600kHz). Changing repeated_start from true to false has no effect.
Is there anything else that can be done to make this setup work? Thanks.