lpcware

LPC1113 as i2c slave

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by andrewjfox on Mon Mar 24 17:14:55 MST 2014
Hi All,

I'm having trouble setting the micro to function correctly as an i2c slave. The problem is that the device responds to any address on the bus, rather than only the matching slave address set in the ADR0 register. Everything else like the interrupt and the state handling works ok. Attached is initialisation code, where I set the address matching register and mask to my slave address (in this sample it is 0x58).

BTW I've been debugging using a Saleae 8 channel Logic analyser (awesome debug tool at reasonable price), so can see exactly what's happening on the i2c bus.


NVIC_DisableIRQ(I2C_IRQn);

LPC_IOCON->PIO0_4 = 0x1;// enable I2C pins
LPC_IOCON->PIO0_5 = 0x1;

// enable I2C clock, deassert peripheral reset
SET_BITS(LPC_SYSCON->SYSAHBCLKCTRL,SYSAHBCLKCTRL_I2C);
SET_BITS(LPC_SYSCON->PRESETCTRL,(0x1<<1));

LPC_I2C->CONCLR  = I2C_CON_STA | I2C_CON_STO | I2C_CON_SI | I2C_CON_AA | I2C_CON_EN;

/* i2c bit freq = i2c PCLK / (SCLL + SCLH)
* for SCLL = SCLH = PCLK / i2c freq / 2
*/
LPC_I2C->SCLL = (SystemCoreClock/I2C_FREQ)/2;
LPC_I2C->SCLH = LPC_I2C->SCLL;

LPC_I2C->MMCTRL = 0; // disable monitor mode
LPC_I2C->ADR0 = 0; LPC_I2C->ADR1 = 0; LPC_I2C->ADR2 = 0; LPC_I2C->ADR3 = 0;
LPC_I2C->MASK0 = 0;LPC_I2C->MASK1 = 0;LPC_I2C->MASK2 = 0;LPC_I2C->MASK3 = 0;

LPC_I2C->ADR0 = 0x58;  // disable General Call bit0
LPC_I2C->MASK0 = 0x0FE;
LPC_I2C->CONSET = I2C_CON_EN | I2C_CON_AA;

NVIC_EnableIRQ(I2C_IRQn);

Anyone have success getting the micro to function as a slave, and only responding to it's matching slave address? I can't find any notes on the NXP site, if anyone knows of a bug in the hardware let me know.

Thanks in advance

Outcomes