Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Wed Sep 23, 2015 11:32 am |
|
|
What's your problem?.
It is fairly standard I2C, except for the checksum:
Code: |
#define CHIP_ADDRESS 0xE6
#define READ 1
int1 read_registers(int8 start_register,char * buffer, int8 count)
{
int8 csum=0;
i2c_start();
i2c_write(CHIP_ADDRESS);
i2c_write(start_register);
i2c_start();//repeated start
i2c_write(CHIP_ADDRESS | READ); //read
while(count--)
{
*buffer=i2c_read();
csum ^= *buffer;
buffer++;
} //note chip does not require a NACK
i2c_stop();
i2c_start();
i2c_write(CHIP_ADDRESS | READ); //now read checksum
csum ^= i2c_read();
i2c_stop();
return csum; //returns 0 if checksum OK
}
|
This transfers 'count' bytes into the buffer, starting at 'start_register', and returns 0 if the checksum matches. |
|