lpcware

LPC17xx I2C

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by furkan.yuksel on Fri Jul 15 02:28:49 MST 2011
Hi,

I just tried to write my own i2c driver, but I couldn't even make my program get into I2C_IRQ.

My initializatin code for I2C1:
void I2CInit( )
{
      LPC_SC->PCONP |= (1 << 19);

      /* set PIO0.0 and PIO0.1 to I2C1 SDA and SCL */
      /* function to 11 on both SDA and SCL. */
      LPC_PINCON->PINSEL0 &= ~((0x3<<0)|(0x3<<2));
      LPC_PINCON->PINSEL0 |= ((0x3<<0)|(0x3<<2));
      LPC_PINCON->PINMODE0 &= ~((0x3<<0)|(0x3<<2));
      LPC_PINCON->PINMODE0 |= ((0x2<<0)|(0x2<<2));        /* No pull-up no pull-down */
      LPC_PINCON->PINMODE_OD0 |= ((0x01<<0)|(0x1<<1));    /* Open drain */

      /*--- Clear flags ---*/
      LPC_I2C1->CONCLR = I2C_AA | I2C_SI | I2C_STA | I2C_I2EN;

      LPC_I2C1->SCLL   = I2SCLL_SCLL;
      LPC_I2C1->SCLH   = I2SCLH_SCLH;

      LPC_I2C1->ADR0 = Slave_ADDR1_0;

      /* Enable the I2C Interrupt */
      NVIC_EnableIRQ(I2C1_IRQn);
      LPC_I2C1->CONSET = I2C_I2EN | I2C_AA;

}


My write code:

int i, timeout_flag;

    SLV_ADDR = slave_addr;

    for (i=0; i<data_length; i++)
        Master_Write_Buffer = write_buf;

    Master_Write_Length = data_length;
    Master_Write_Index = 0;


    I2C_Ready=0;
    LPC_I2C1->CONSET = I2C_STA;


any ideas?

Outcomes