lpcware

No I2C Clock signal

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by g_mocken on Thu Jul 16 07:22:19 MST 2015
Hi,

I am trying to use I2C on LPC4074. Below is a rough sketch of my initialization, which I derived from the "periph_i2c" sample code (which is designed for LPC43xx, though):

void I2C0_IRQHandler(void) {
if (Chip_I2C_IsMasterActive(I2C0)) {
Chip_I2C_MasterStateHandler(I2C0);
}
else {
Chip_I2C_SlaveStateHandler(I2C0);
}
}

void test(void) {


Chip_IOCON_Init(LPC_IOCON);
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 30, IOCON_FUNC4 | IOCON_OPENDRAIN_EN);
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 31, IOCON_FUNC4 | IOCON_OPENDRAIN_EN);

Chip_I2C_Init(I2C0);
Chip_I2C_SetClockRate(I2C0, 400000);
Chip_I2C_SetMasterEventHandler(I2C0, Chip_I2C_EventHandler);
NVIC_ClearPendingIRQ(I2C0_IRQn);
NVIC_EnableIRQ(I2C0_IRQn);

static uint8_t buf[10];
static I2C_XFER_T xfer={.slaveAddr=I2C_ADDR_7BIT, .txBuff=buf, .txSz=sizeof(buf)};
Chip_I2C_MasterSend(I2C0, xfer.slaveAddr, xfer.txBuff, xfer.txSz);
}


When I single-step test() and put a scope on SDA and SCL, then I notice a high->low transition on SDA on the last line of the following LPCOpen function, which is called by Chip_I2C_MasterSend():

/* Enable I2C and start master transfer */
STATIC INLINE void startMasterXfer(LPC_I2C_T *pI2C)
{
/* Reset STA, STO, SI */
pI2C->CONCLR = I2C_CON_SI | I2C_CON_STO | I2C_CON_STA | I2C_CON_AA;

/* Enter to Master Transmitter mode */
pI2C->CONSET = I2C_CON_I2EN | I2C_CON_STA;
}


I would expect the clock line to show the same transition in order to make this a START condition, but SCL stays high, no interrupt trigers and the code hangs in Chip_I2C_EventHandler(), probably waiting for the START condition to complete.


Do you have any idea what could be wrong or missing in this setup?

Outcomes