lpcware

Low level program for I2C

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by salamlora1 on Sat Jun 07 05:30:11 MST 2014
Low level program for I2C
Hi
I’m trying to write a low level program for LPC812 I2C
But it’s not working and both of my SDA and SCL are low (zero)
I can’t fine my mistake in my program? plz guide me
/////////////////////////////////////////////
I2CC:
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<5); //1 clock for i2c
LPC_SYSCON->PRESETCTRL |= (0x1<<6);//2 reset the i2c
regVal = LPC_SWM->PINASSIGN7 & ~(0xFFUL<<24); //4
LPC_SWM->PINASSIGN7 = regVal | (2 << 24);/* P0.2 is I2C SDA, ASSIGN0(31:24) */
regVal = LPC_SWM->PINASSIGN8 & ~(0xFF<<0);
LPC_SWM->PINASSIGN8 = regVal | (3 << 0);/* P0.3 is I2C SCL. ASSIGN0(7:0) */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<5);//5
LPC_IOCON->PIO0_2 =(1<<10); //6  setting the iocon open drain mode
LPC_IOCON->PIO0_3 =(1<<10);//6 setting the iocon open drain mode
LPC_I2C->DIV = 10000;//7 32mh / 10000
LPC_I2C->MSTTIME = 0 ;//8 2 clocks. Minimum SCL high time is 2 clock of the I2C clock pre-divider.
LPC_I2C->CFG =0;
LPC_I2C->CFG = 1;//9 master mode
LPC_I2C->MSTDAT=0xaa; //10 the data its must to send i hope!
LPC_I2C->MSTCTL =2;//11 master start
delay(1000);
LPC_I2C->MSTDAT=0xaa; //10 the data its must to send i hope!
LPC_I2C->MSTCTL =1;//11 Master Continue. This bit is write-only.
delay(1000);
goto I2CC;

Outcomes