Low level program for I2C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Low level program for I2C

1,248 Views
lpcware
NXP Employee
NXP Employee
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;
Labels (1)
0 Kudos
Reply
3 Replies

1,173 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Wed Jun 11 01:04:51 MST 2014
Have you considered just looking at the example code provided in LPCOpen?

http://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc8xx-packages

Regards,
LPCXpresso Support
0 Kudos
Reply

1,173 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Wed Jun 11 00:46:05 MST 2014
Any ting is wrung with my post why no one answering to me???!!!!
0 Kudos
Reply

1,173 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Mon Jun 09 00:49:59 MST 2014
Hi no one answering
Some one noob need help plz !
I cheng the program to below
And the SDA and ACL have pulse but in the USART I see the 0xAA or anything else I send on LPC_I2C->MSTDAT




LPC_SYSCON->SYSAHBCLKCTRL |= (1<<5); //1 clock for i2c
LPC_SYSCON->PRESETCTRL |= (0x1<<6);//2 clear resset the i2c
LPC_I2C->INTENSET=0; // 3 disable all interrupts
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 = 0xff0Dff03;/* 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_GPIO_PORT->DIR0 |= (1 << 2);
LPC_IOCON->PIO0_3 |=(1<<10);//6 setting the iocon open drain mode
LPC_GPIO_PORT->DIR0 |= (1 << 3);
LPC_I2C->DIV = 0x100;//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
int mmm;
loooop:
LPC_I2C->MSTDAT=0xad;//address for AT24C512C  (1-0-1-0-A2-A1-A0-W/R )
LPC_I2C->MSTCTL =2;
while(LPC_I2C->STAT ==0);
LPC_I2C->MSTDAT=0x12;//first byte of address
LPC_I2C->MSTCTL =1;
while(LPC_I2C->STAT ==0);
LPC_I2C->MSTDAT=0xaa;// second byte of address
LPC_I2C->MSTCTL =1;=
while(LPC_I2C->STAT ==0);
LPC_I2C->MSTCTL =1;
while(LPC_I2C->STAT ==0);
mmm = LPC_I2C->MSTDAT; // hear must the data in the eeprom
LPC_USART0->TXDATA = mmm;
goto loooop;


PLZ heeeeeeeeeeeeeeelp
0 Kudos
Reply