#define I2C_SLAVE_ADDR 0x0055 #define I2C_NUMBYTES 1 void main(void) { InitSysCtrl(); InitI2CGpio(); bool flag = true; I2CA_Init_master(); for(;;) { while(GpioDataRegs.GPBDAT.bit.GPIO44 == 0 && flag ) { GREENLED_ON ; I2CA_WriteData(); GREENLED_OFF ; flag = false; } } void I2CA_Init_master(void) { I2caRegs.I2CSAR = I2C_SLAVE_ADDR;// Slave address - I2caRegs.I2CPSC.all = 6; // Prescaler - need 7-12 Mhz on module clk I2caRegs.I2CCLKL = 10; // NOTE: must be non zero I2caRegs.I2CCLKH = 5; // NOTE: must be non zero I2caRegs.I2CIER.all = 0; I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset DELAY_US(10); return; } void I2CA_WriteData(void){ Uint16 i; // while (I2caRegs.I2CMDR.bit.STP == 1) // { // }; I2caRegs.I2CSAR = I2C_SLAVE_ADDR; //slave address register I2caRegs.I2CCNT = I2C_NUMBYTES ; //data count is 1 byte I2caRegs.I2CDXR = 0xf0; //The only data byte I am trying to send I2caRegs.I2CMDR.bit.TRX = 1; I2caRegs.I2CMDR.bit.MST = 1; I2caRegs.I2CMDR.bit.FREE = 1; I2caRegs.I2CMDR.bit.STP = 1; //creating a stop condition will free the BUS thus turning the BB == 0. I2caRegs.I2CMDR.bit.STT = 1; // As soon as you start the Start Bit the BB == 1 becomes busy again. return ; }