I do write operation.
unsigned int I2C0_Wait(void)
{
unsigned int timeout = 0;
while((I2C0_S & I2C_S_IICIF_MASK)==0)
{
timeout++;
if(timeout > I2C_TIMEOUT)
return I2C_ERROR;
}
I2C0_S |= I2C_S_IICIF_MASK;
return 0;
}
void MAX7300_Write(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data)
{
uint8_t slave_address = (slave_addr<<1) & 0xFE;
//START
I2C0_C1 |= I2C_C1_MST_MASK;
I2C0_C1 |= I2C_C1_TX_MASK;
I2C0_D = slave_address;
I2C0_Wait();
I2C0_D = reg_addr;
I2C0_Wait();
I2C0_D = *data;
I2C0_Wait();
//STOP
I2C0_C1 &= ~I2C_C1_MST_MASK;
I2C0_C1 &= ~I2C_C1_TX_MASK
while (I2C0_S & I2C_S_BUSY_MASK) ;
}
After stop the busy flag is not cleared – I stay in while (I2C0_S & I2C_S_BUSY_MASK).