Grzegorz Warchol

Problem with I2C in  LPCExpresso 1347 - STATUS BUSY

Discussion created by Grzegorz Warchol on Jan 3, 2018
Latest reply on Jan 4, 2018 by Kerry Zhou

Hello,

I have LPCExpresso 1347 board and I want to run I2C0.

So far I have this part of code, and everything looks ok, and should working but my problem is that When I want to transmit byte Program stops and wait in function  lines:

 

       while (*stat == I2C_STATUS_BUSY) {

             if (Chip_I2C_IsStateChanged(id)) {

                    Chip_I2C_MasterStateHandler(id);

             }

       }

 

 

In function Chip_I2C_EventHandlerPolling.

On Oscyloscope I can see that on both pins I means pin0_4 and pin0_5 are in high state. There is no CLK and Data signal at all.

Below I include my code.

Thank you very much if anybody know what it could be !

 

 

 

static void Init_I2C_PinMux(void)

{

 

       Chip_IOCON_PinMux(LPC_IOCON, 0, 4, IOCON_MODE_INACT, IOCON_FUNC1);

       Chip_IOCON_PinMux(LPC_IOCON, 0, 5, IOCON_MODE_INACT, IOCON_FUNC1);

}

 

static void i2c_state_handling(I2C_ID_T id)

{

       if (Chip_I2C_IsMasterActive(id)) {

             Chip_I2C_MasterStateHandler(id);

       } else {

             Chip_I2C_SlaveStateHandler(id);

       }

}

 

 

static void i2c_set_mode(I2C_ID_T id, int polling)

{

       if(!polling) {

             mode_poll &= ~(1 << id);

             Chip_I2C_SetMasterEventHandler(id, Chip_I2C_EventHandler);

             NVIC_EnableIRQ(I2C0_IRQn);

       } else {

             mode_poll |= 1 << id;

             NVIC_DisableIRQ(I2C0_IRQn);

             Chip_I2C_SetMasterEventHandler(id, Chip_I2C_EventHandlerPolling);

       }

}

static void i2c_app_init(I2C_ID_T id, int speed)

{

       Init_I2C_PinMux()

       /* Initializ I2C */

       Chip_I2C_Init(id);

       Chip_I2C_SetClockRate(id, speed);

       /* Set default mode to interrupt */

       i2c_set_mode(id, 1);

}

 

 

int main(void) {

 

    ....

       i2c_app_init(I2C0, SPEED_100KHZ);

 

 

 

    while(1) {

       unsigned char temp_i2c_send[2];

       unsigned char adress = 0xA1;

       temp_i2c_send[0] = 0x11;

       Chip_I2C_MasterSend(I2C0, adress, temp_i2c_send, 1);

 

    }

    return 0 ;

}  

Outcomes