Hi,
I am trying to follow the flowchart given in the datasheet to transmit 4 bytes out from I2C. However, I can only manage to see 0x34 and 0x78 being transmitted out from the scope while the other 2 bytes lost in the air. Below is the code and flowchart for reference. Need a second pairs of eyes to see what I have missed in my code. Thanks.
My code:
int main(void)
{
//Enable clock to I2C and GPIO Port A
*((uint32_t *)(SYSCTL_RCGCI2C)) |= (0x01 << 9);
*((uint32_t *)(SYSCTL_RCGCGPIO)) |= (0x00001 << 0);
//Wait for the SSI Interface and GPIO Port A Peripheral to be ready
while(!(*(uint32_t *)(SYSCTL_PRI2C) & (0x001 << 9)));
while(!(*(uint32_t *)(SYSCTL_PRGPIO) & (0x00001 << 0)));
//Configure the GPIO alternate function as I2C
*((uint32_t *)(GPIO_PORTA_AHB + GPIO_O_AFSEL)) |= (0x03 << 0);
*((uint32_t *)(GPIO_PORTA_AHB + GPIO_O_ODR)) |= (0x01 << 1);
*((uint32_t *)(GPIO_PORTA_AHB + GPIO_O_PCTL)) = (0x2 << 4 | 0x2 << 0);
*((uint32_t *)(GPIO_PORTA_AHB + GPIO_O_DEN)) |= (0x03 << 0);
//Configure the clock source to use PIOSC
*((uint32_t *)(SYSCTL_PLLFREQ0)) |= (0x1 << 23);
while(!(*(uint32_t *)(SYSCTL_PLLSTAT)));
*((uint32_t *)(SYSCTL_PLLFREQ0)) &= ~(0x1 << 23);
//Configure I2C as master mode
*((uint32_t *)(I2C9 + I2C_O_MCR)) |= (0x1 << 4);
//Configure SCL clock speed to 100kHz
*((uint32_t *)(I2C9 + I2C_O_MTPR)) = 0x08;
//Configure the slave address and operate in transmit mode
*((uint32_t *)(I2C9 + I2C_O_MSA)) = (0x76 << 1 | 0x0 << 0);
//Wait until the bus is idle
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000001);
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000040);
//Transmit 1 byte of data
*((uint32_t *)(I2C9 + I2C_O_MDR)) = 0x12;
//Initiate 1 byte transmission
*((uint32_t *)(I2C9 + I2C_O_MCS)) = 0x03;
//Wait until the I2C is idle and no error
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000001);
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000002);
//Transmit 1 byte of data
*((uint32_t *)(I2C9 + I2C_O_MDR)) = 0x34;
//Initiate 1 byte transmission
*((uint32_t *)(I2C9 + I2C_O_MCS)) = 0x01;
//Wait until the I2C is idle and no error
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000001);
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000002);
//Transmit 1 byte of data
*((uint32_t *)(I2C9 + I2C_O_MDR)) = 0x56;
//Initiate 1 byte transmission
*((uint32_t *)(I2C9 + I2C_O_MCS)) = 0x01;
//Wait until the I2C is idle and no error
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000001);
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000002);
//Transmit 1 byte of data
*((uint32_t *)(I2C9 + I2C_O_MDR)) = 0x78;
//Initiate 1 byte transmission
*((uint32_t *)(I2C9 + I2C_O_MCS)) = 0x05;
//Wait until the I2C is idle and no error
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000001);
while((*(uint32_t *)(I2C9 + I2C_O_MCS)) & 0x00000002);
while(1);
}