LPC1113 as i2c slave

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC1113 as i2c slave

969 次查看
lpcware
NXP Employee
NXP Employee
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
标签 (1)
0 项奖励
回复
1 回复

863 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by andrewjfox on Wed Mar 26 22:23:45 MST 2014
Solved my own problem, though I'd post it just in case anyone has some trouble

The manual description of the slave address MASK bits is counter-intuitive. I read it as setting the MASK bits enables comparison on that bit, and so set them to 1, however after experimenting I've found that they have to be 0 for slave address to be matched. Ie Setting the mask bit disables comparison on that bit.



0 项奖励
回复