Expecting the slave to ACKnowledge and return data, but it does not. This is my protocol. This is my Datasheet
The datasheet mentions \"The slave will answer by sending
I'm not sure what your root issue is here. What are the symptoms you are having? What kind of output do you have on your UART?
As others have said, your buffer
variable is too small to hold anything of value as a C string. itoa
(AVR libc entry) usually provides a null-terminated string, so you'll need to be at least big enough for all the characters as well as the null value. You may be having an issue overflowing the buffer, in which case you should have a simple solution.
Your use of uin8_t
means you should be allocating enough space for the representation of up to 255. You need 3 characters to represent the full range, as well as one character for the null character. Change your code to read char buffer[4];
and see if that improves the issues you are having.
If the I2C protocol implementation is in error, that will be harder to diagnose without accurate information on where the error is. A logic analyser should help here if you have access to one.
EDIT:
I just took a look at the datasheet and your method of i2c_start(0x5A)
with consecutive i2c_read_ack()
s seems to be correct. However, based on your linked protocol, you are probably just seeing "Error" on your UART as i2c_start()
returns 0
for a successful start transaction and you check if(i2c_start(I2C_READ))
when you should be testing for if(! i2c_start(I2C_READ))
in getVal()
.
You also seem to have some unnecessary uint8_t
casts based on your linked i2c_master.c gist. I'd suggest just using the Arduino IDE if this really is an Arduino compatible board and see if you can get a simple I2C example to work with the sensor to prove out your access methodology.