|
Hi Jerene,
A simple code for reading the location 0x01 would look something like this:
#include<device.h>
#define SLAVE_ADDRESS 0x00 /* Give the appropriate Slave Address */
uint8 shunt_volt[1] = {0x01}; /* The address of the Shunt Voltage register */
uint8 read_value[2]; /* To store the read value */
void main()
{
I2C_Start();
CyGlobalIntEnable();
I2C_MasterWriteBuf(SLAVE_ADDRESS, shunt_volt, 1, I2C_MODE_NO_STOP); /* This sets the pointer to Shunt Voltage register whose address is 0x01 */
while(I2C_MasterStatus() == I2C_MSTAT_XFER_INP); /* Waits till the transfer is complete */
I2C_MasterReadBuf(SLAVE_ADDRESS, read_value, 2, I2C_MODE_REPEAT_START ); /* read_value will hold the two bytes read. This begins with a repeat start */
while(I2C_MasterStatus() == I2C_MSTAT_XFER_INP); /* Waits till the transfer is complete */
}
|