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; } |
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; |