Hello,
I have recently encountered my sensors showing an I2C error: 2. Looking at google, datasheets, and forums, I have not found a clear answer of what could be causing this problem. My I2C devices are recognized and the addresses I expect show up when I scan for them, however, I cannot get any readings from my sensors. I am using 7 pin hall effect encoders by the way.
I understand it has something to do with NACK, or not-acknowledged so that the data was not read properly or something. I was just wondering if someone could give me a clear explanation of what I2C error 2 really means and what methods I could go about fixing it.
Code and wiring diagram please.
my guess is in the code... please post as requested.
Why do you think that this is an error code? Errors usually have negative values.
Look at the documentation of the method or function returning the value.
There are two situations in twi.c which can return an error code of 2.
The first is if a NACK is received when sending the address during a write of data.
The second is from the twi_transmit function which writes data to a buffer. In this case the error means the device is not in slave mode.
I've never had either of them happen so I haven't had to sort out the specifics of how/why the error occurred.
Pete
I'm using example code to test out my sensor. Here is the link
As for wiring, I'm using 2.0k pull-ups for SDA, SCL. I have a 100nF capacitor from 5V to GND, a 10uF from 3V3 to GND, have A1, A2 pulled high (all these two should control is the address), and am using a Teensy 3.6 MCU. I have also tried this on an UNO and have the same issue.
Putting in examples you found online does not help us to figure out what is going on for your situation.
The address may be what you expect but have you made sure that it is what the library expects?
#define AS5048_ADDRESS 0x40 // 0b10000 + ( A1 & A2 to GND)
Pete
1 Like
rzkennedy:
As for wiring, I'm using 2.0k pull-ups for SDA, SCL.
Have you tried 4.7k or 10k ?
Since the error might be as simple as using common pull up's for I2C, that might take away one problem.
With one sensor and short cables it mostly works without pullup. Two sensors and no pullup might work, else I remember that 10 kOhm was a standard value.
el_supremo:
The address may be what you expect but have you made sure that it is what the library expects?
#define AS5048_ADDRESS 0x40 // 0b10000 + ( A1 & A2 to GND)
Pete
Ok that makes sense. Error is gone. In theory, if I wanted to implement multiple sensors with multiple addresses I would just have to edit the .h file make separate definitions for each sensor address. Thank you very much.
The standard value for pullups on a 5V system is 4.7k. But for a Teensy 3.6, which is a 3V3 system, a 3.3k is probably "standard".
Pete
What does the I2C definition say, stated in the 1980s?