I2C Constant NACK

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

I2C Constant NACK

3,596 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Fri Oct 14 02:28:25 MST 2011
Hello,

I have a LPC1769 that I am using I2C on. I have been working on the code to set up my accelerometer and gyro. I can get the code to send a start signal, but all I receive are NACK signals. I think I have the clock right, anybody have any ideas?

Thanks,
J
0 Kudos
Reply
24 Replies

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Sat Oct 15 12:05:16 MST 2011

Quote:
I2C1Init( );            /* initialize I2c2 */

The comment and code don't seem to match.
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Sat Oct 15 10:00:11 MST 2011
Whew, figured it out, so it seems like the code had to pull up resistors set, and it was in floating mode. When I removed this part of the code, the clock looks perfect now. I get a frequency of 95Khz. Zero, I appreciate the help, I understand this is not a school, and I prefer the help that you guys give me. I dont like it when people give you the answer, so I appreciate you pointing me in the right direction. Thanks all!!:D




  /* set PIO0.10 and PIO0.11 to I2C2 SDA and SCL */
  /* function to 10 on both SDA and SCL. */
  LPC_PINCON->PINSEL0 &= ~((0x03<<20)|(0x03<<22));
  LPC_PINCON->PINSEL0 |= ((0x02<<20)|(0x02<<22));
 // LPC_PINCON->PINMODE0 &= ~((0x03<<20)|(0x03<<22));
  //LPC_PINCON->PINMODE0 |= ((0x02<<20)|(0x2<<22));
  LPC_PINCON->PINMODE_OD0 |= ((0x01<<10)|(0x1<<11));
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Sat Oct 15 09:50:03 MST 2011
That's what I am trying to figure out, why the clock frequency is not what it should. I know that it should be 100kHz, I'm trying to understand why it is not.
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Oct 15 09:46:05 MST 2011

Quote: jherrera8
When I use my logic analyzer, I get inconsistent readings



If you can't measure your SCL frequency, I can't help you. You've calculated your SCL frequency with SCLL/SCLH = 90. So your SCL frequency should be 100kHz at PCLK 18MHz. That's the first thing you have to measure :eek:
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Sat Oct 15 09:34:11 MST 2011
When I use my logic analyzer, I get inconsistent readings. I get values between 50Hz and 100Hz. I know how to disable open-drain, but I still dont understand what you want me to do about the resistors. I appreciate all the help,

J
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Oct 15 09:14:59 MST 2011
And even worse, you don't do what you've been asked for :eek:

Step #1: What is your measured SCL frequency :confused: And don't answer with words like 'think', 'believe' or 'should' :)

Note: Could be a good idea to read the user manual and google a little bit. This is a forum and not a school :rolleyes:
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Sat Oct 15 08:51:54 MST 2011
Im sorry, I dont understand what you mean. So I will remove the sensor, but how do I disable open drain , and what do you mean about the resistors? Sorry but I am just new to all of this.

Thanks,
J
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Oct 15 08:39:49 MST 2011

Quote: jherrera8
Edit: After looking, is I2cPADCFG only used for I2C0 ?



Of course, that's the confusing the confused part of this game show :mad:

And your confusing the confused part is your posted picture :eek: Did you meanwhile measure your SCL frequency? If this picture is showing the right time scale you have a serious timing problem.
Otherwise it looks like an output problem and it could be a good idea to disconnect your I2C device and scope the signals again (of course with selected pullup and disabled open drain) :eek:
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Fri Oct 14 20:18:34 MST 2011
I am very sure that it is set to 0x5a, and I don't believe I have I2CPADCFG set. Where would that be set? I don't think I have that so how and where should I set it?

Edit: After looking, is I2cPADCFG only used for I2C0 ? I am using SDA2 and SCL2.

Thanks,

J
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Fri Oct 14 19:44:00 MST 2011

Quote:
The system clock seems to be at 72Mhz, I think that would put the PClk  around 18Mhz, so the values I chose for SCLL and SCHL are 0x5a

Are you [U]sure[/U] that I2SCLL_SCLL and I2SCLL_SCLH are both [B]really[/B] 0x5A?
What did you set [I]I2CPADCFG[/I] to?
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Fri Oct 14 16:16:45 MST 2011
OK, here is the screen shot of the signals, like I said, I don' think the clock is right, so no matter what I put on the bus, it wont work. Any ideas?

Thanks

[IMG]http://i.imgur.com/4VdI8.png[/IMG]
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Fri Oct 14 14:47:06 MST 2011
I did, and it does the same thing. That is why I am starting to think there is something wrong with the clock. Like I said, I don't think the clock signal is right. If it is the clock, it would be a good reason why nothing is happening. The status register says 0x08, then 0xf8, then finally 0x38. Is there a way to see if the clock is correct. I am getting my logic analyzer back shortly, and I will post a pic. Until then is there something else I can check....

Thanks
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Fri Oct 14 14:19:24 MST 2011
Do you have the 1769 LPCXpresso board? If you do you should start out trying to read/write to the I2C eeprom on it.
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Fri Oct 14 11:48:24 MST 2011
HAHAHA, so when in debug, I can see the value of the system clock is 72MHz. Am I correct in saying the Pclk is 72Mhz/4? I used the equation in the the documents to calculate the SCLL value. Does this seem right? What other settings are there for the clock besides the SCLL and SCLH values? I don't think my logic analyzer clocks the frequency accurately, it tells me about 60Hz.When I change the SCLL and SCLH values the clock doesn't seem to change much.

Thanks for all the help,

J
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Oct 14 11:31:01 MST 2011

Quote:

The system clock seems to be at 72Mhz, I think that would put the PClk around 18Mhz, so the values I chose for SCLL and SCHL are 0x5a

Is this a game show? Guess frequency and resulting SCL and win a brand new washing machine?

Could be a good idea to measure SCL, would increase the chance to win the prize :rolleyes:
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Fri Oct 14 11:03:19 MST 2011
Hahaha whoops, I think I might have been up too late working on this. As for the scope, I let a friend borrow it for a few hours. What I am seeing is the data signals look good, but the clock duty cycle seems way too small. The time that the signal is high seems way way too short. On the example scope, it shows that clock and data lines are somewhat the same size. My clock triggers regularly, but seems like it spikes more than a square wave. I hope this is enough to help until I get my scope back.

Thanks so much,

The system clock seems to be at 72Mhz, I think that would put the PClk around 18Mhz, so the values I chose for SCLL and SCHL are 0x5a

void I2C2Init( void )
{
  LPC_SC->PCONP |= (1 << 26);

  /* set PIO0.10 and PIO0.11 to I2C2 SDA and SCL */
  /* function to 10 on both SDA and SCL. */
  LPC_PINCON->PINSEL0 &= ~((0x03<<20)|(0x03<<22));
  LPC_PINCON->PINSEL0 |= ((0x02<<20)|(0x02<<22));
  LPC_PINCON->PINMODE0 &= ~((0x03<<20)|(0x03<<22));
  LPC_PINCON->PINMODE0 |= ((0x02<<20)|(0x2<<22));/* No pull-up no pull-down */
  LPC_PINCON->PINMODE_OD0 |= ((0x01<<10)|(0x1<<11));

  /*--- Clear flags ---*/
  LPC_I2C2->CONCLR = I2CONCLR_AAC | I2CONCLR_SIC | I2CONCLR_STAC | I2CONCLR_I2ENC;

  LPC_I2C2->SCLL   = I2SCLL_SCLL;
  LPC_I2C2->SCLH   = I2SCLH_SCLH;





 /* Enable the I2C Interrupt */
 NVIC_EnableIRQ(I2C2_IRQn);

 LPC_I2C2->CONSET = I2CONSET_I2EN ;
 return;
}
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Oct 14 10:51:00 MST 2011

Quote: jherrera8
...when I scope mine, it doesn't look like that...:confused:



You didn't  post your i2c config and you don't describe what you've scoped, so only a clairvoyant could help you :rolleyes:
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Fri Oct 14 10:25:03 MST 2011
I think my issue is with the clock, because when I scope mine, it doesn't look like that. I know that the address should be 0xA6, when I copied the code I was trying everything I could. That code is very helpful , but like I said, I think I'm having trouble with the clock.

Edit: Could you help me setup a proper clock


Thanks,
J
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Oct 14 09:56:37 MST 2011

Quote:

An alternate I2C address of 0x53 (followed by the R/W bit) can be chosen by grounding the SDO/ALT ADDRESS pin (Pin 12). This translates to 0xA6 for a write and 0xA7 for a read.

Is Pin 12 grounded?

Figure 9 shows correct address usage and starts always with writing :eek::eek:

Why don't you start with this code :confused::confused:

http://knowledgebase.nxp.com/showthread.php?p=970
0 Kudos
Reply

3,389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jherrera8 on Fri Oct 14 09:22:19 MST 2011
Ok, so the chip is an IMU from sparkfun.com, and it has an accelerometer and a gyro. They both should work independently. I have tried fooling around with the code , and now I am not getting anything after I load the device address on the bus. Below are the links to the documents. Please help, slowly going insane....:confused:

http://http://www.sparkfun.com/datasheets/Sensors/Gyro/PS-ITG-3200-00-01.4.pdf

http://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345.pdf

http://www.sparkfun.com/datasheets/Sensors/IMU/6DOF-Digital-v10.pdf
0 Kudos
Reply