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 bytes with MSB first. Byte0 and byte1 contain the prediction value. All bytes are acknowledged by the master."
Edit: Source Library
Also FYI I'm on an Arduino Fio but I am not inheriting the Arduino library.
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <uart.h>
#include <i2c_master.h>
#define LED PB5
#define I2C_READ 0x5A
char buffer[1];
//char data[9];
uint16_t val = 0;
uint8_t status = 0;
void getVal()
{
if(i2c_start(I2C_READ))
{
uart_puts("Start ");
val = ((uint8_t)i2c_read_ack())<<8;
val |= i2c_read_ack();
status = ((uint8_t)i2c_read_nack());
i2c_stop();
} else
{
uart_puts("Error");
i2c_stop();
}
}
int main(void)
{
init_uart(57600);
i2c_init();
DDRB = _BV(5);
for(;;)
{
getVal();
itoa(status, buffer, 10); //convert decimal to string base 10
uart_puts(buffer);
PORTB = 0xFF;
_delay_ms(500);
PORTB = 0x00;
_delay_ms(500);
}
return 0; /* never reached */
}
Edit Revised:
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <uart.h>
#include <i2c_master.h>
#define LED PB5
#define I2C_READ 0x5A
char buffer[10];
//char data[9];
uint16_t val = 0;
uint8_t status = 0;
{
if(!i2c_start(I2C_READ))
{
uart_puts("Error");
i2c_stop();
} else
{
uart_puts("Start ");
i2c_start((IAQ_ADDR << 1) + 1); //i2c_start(0xB5);
val = ((uint8_t)i2c_read_ack())<<8;
val |= i2c_read_ack();
status = ((uint8_t)i2c_read_nack());
i2c_stop();
}
}
int main(void)
{
init_uart(57600);
i2c_init();
DDRB = _BV(5);
for(;;)
{
getVal();
itoa(status, buffer, 10); //convert decimal to string base 10
uart_puts(buffer);
PORTB = 0xFF;
_delay_ms(500);
PORTB = 0x00;
_delay_ms(500);
}
return 0; /* never reached */
}
bufferhas size1, so youritoaoverflows the buffer. - M.M