I have no trouble reading a single byte from a register on I2C device, but my following problem obviously has some bug when reading 2 bytes. Could anyone give me a pointer? Thanks!
int I2CReceive(uint32_t slave_chn, uint8_t reg, uint8_t num_of_args)
{
int iTemp;
//specify that we are writing (a register address) to the slave device
I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS_BASE+slave_chn, false);
//specify register to be read
I2CMasterDataPut(I2C2_BASE, reg);
//send control byte and register address byte to slave device
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_SEND);
//wait for MCU to finish transaction
while(I2CMasterBusy(I2C2_BASE));
//SysCtlDelay(6000);
//specify that we are going to read from slave device
I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS_BASE+slave_chn, true);
if (num_of_args==1){
//This section works!
//send control byte and read from the register we
//specified
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
//wait for MCU to finish transaction
while(I2CMasterBusy(I2C2_BASE));
//return data pulled from the specified register
return (short)I2CMasterDataGet(I2C2_BASE);
}
else{
//num_of_args==2, this won't work
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
//wait for MCU to finish transaction
while(I2CMasterBusy(I2C2_BASE));
//return data pulled from the specified register
iTemp= I2CMasterDataGet(I2C2_BASE);
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
//wait for MCU to finish transaction
while(I2CMasterBusy(I2C2_BASE));
//return data pulled from the specified register
iTemp= iTemp| I2CMasterDataGet(I2C2_BASE)<<8;
return iTemp;
}
}


