Problem with I2C in LPCExpresso 1347 - STATUS BUSY

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with I2C in LPCExpresso 1347 - STATUS BUSY

509 Views
grzegorzwarchol
Contributor I

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 ;

}  

Tags (3)
0 Kudos
1 Reply

374 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Grzegorz Warchol,

    Do you write a 1 to PRESETCTRL register before you access I2C peripherals?

   If not, please add this code before you initialize the I2C module:

Chip_SYSCTL_DeassertPeriphReset(RESET_I2C0); //before accessing the I2C peripherals, ensure the reset signal to the I2C are deasserted.

pastedImage_1.png

I have test our lpcopen code for LPC1347, it also lack this code, after add the above code, I can make it works, I checked the I2C bus on my side, it already have the data, but I didn't add the slaver, so I2C will have NACK.

  I attached the lpcopen I2C code which works in my side.

This is the I2C bus wave:

pastedImage_2.png

Wish it helps you!

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
----------------------------------------------------------------------------------------------------------------------

0 Kudos