I2C start condition timeout

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

I2C start condition timeout

1,205 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Terje on Thu Apr 19 03:14:32 MST 2012
I am using LPC1343 to read data from a position sensor (NSE-5310) through I2C using the same code as the example from LPCXpresso. This work fine most of the time, but every now and then I receive a timeout from the I2CStart function indicating that I2C never got started and timed out. The LPC1343 and the position sensor are the only units on the bus. What could it be?
0 Kudos
10 Replies

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Apr 19 23:48:40 MST 2012
@Terje.....Ok.. I got it now..
Thanks for sharing the information..:)
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Terje on Thu Apr 19 23:26:25 MST 2012
[FONT=Calibri]I have onlytested this using Master Receiver mode. I use the LPCXpresso dev. Kit LPC1343 connected to NSE-5310 position sensor. I have used an oscilloscope only to check for noise and the state of the SCL line before timeout. I have only tested this using normal mode. (The NSE-5310 does not support fast mode). I don't know what you mean by baseboard, but I am using the JTAG interface on the dev kit, if that is what you mean.[/FONT]

[FONT=Calibri]From fig 35 in the manual one can see that status code 58 is triggered as the last action before ending transmission.Placing a breakpoint in this routine, one will find that this case is not always executed.[/FONT]

[FONT=Calibri]My code is now running as expected.[/FONT]

[FONT=Calibri]Rob: Thanks for the link!![/FONT]
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Apr 19 23:21:36 MST 2012
@Rob65:---  OK....   Thanks for sharing the Link.     ....
So what is the status now. Your I2C is working fine now, rite...?



Thanks & Regards....:)
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Thu Apr 19 23:15:20 MST 2012
Not that amazing at all ...
If you look further you'll find a few more bugs and also will notice that all types of error handling is missing.

I've posted an updated driver a long time ago. Since then there have been at least 5 more releases of the same example code with the same driver instead of a proper updated one.
Sorry, did I call it [I]driver[/I]? It is of course just an example on which you could base your own driver, as I did.

If you are looking for something that might work better, look here. If you look further in the source tree you'll also find an example of its use.
No documentation yet ... that is still under development (together with the slave part of the driver).
You will have to change some initialization code for the 1343 but the I2C peripheral is the same.

Regards,
[INDENT]Rob
[/INDENT]
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Apr 19 21:53:06 MST 2012
Hi..!!

That is really amazing. Congrats... :-))

How are you running the Master and slave code.
Are you using two emulators and then connecting them through SDA and SCL.
Can you see the SCL and SDA on the oscilloscope.
Have you checked its mode(Fast Mode or normal mode) and can you distinguish them.
Is it with baseboard or without a baseboard.:)
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Terje on Thu Apr 19 14:00:17 MST 2012
Okay, I think I solved the problem and found a bug in the I2C example program. I did the following correction to the I2C interrupt handler and now my program is working. (I2CMasterState = DATA_NACK should not be in case 0x50, but in case 0x58)


case 0x50:    /* Data byte has been received, regardless following ACK or NACK */
    I2CSlaveBuffer[RdIndex++] = LPC_I2C->DAT;
    if ( RdIndex < I2CReadLength )
    {   
      I2CMasterState = DATA_ACK;
      LPC_I2C->CONSET = I2CONSET_AA;    /* assert ACK after data is received */
    }
    else
    {
      //I2CMasterState = DATA_NACK;  [COLOR=Red][B] <- Wrong, case 0x58 might not be called[/B][/COLOR]
      LPC_I2C->CONCLR = I2CONCLR_AAC;    /* assert NACK on last byte */
    }
    LPC_I2C->CONCLR = I2CONCLR_SIC;
    break;
    
    case 0x58:
    I2CSlaveBuffer[RdIndex++] = LPC_I2C->DAT;
    I2CMasterState = DATA_NACK;
    LPC_I2C->CONSET = I2CONSET_STO;    /* Set Stop flag */ 
    LPC_I2C->CONCLR = I2CONCLR_SIC;    /* Clear SI flag */
    break;
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Terje on Thu Apr 19 10:23:55 MST 2012
I use 1k8 ohm pullups, and the SCL line doesn’t look noisy. When failing, it takes about 6-7 seconds before it times out and the SCL line is high during this time.
  After having timed out, the program tires to resend the message and succeeds.
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Thu Apr 19 09:36:59 MST 2012
Is the SCL line noisy? What value pullups are being used?
If the SCL line is low when the start bit is set the LPC will wait until it's high before sending the start bit.
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Terje on Thu Apr 19 03:54:45 MST 2012
[FONT=Calibri]Accordingto the description of the I2CStart() function it's a "fatal error"[/FONT]
[FONT=Calibri]I2CStart() :[/FONT]
[FONT=Calibri]"[I]CreateI2C start condition, a timeout value is set if the I2C never gets started, and timed out. It's a fatal error.[/I]"[/FONT]

[FONT=Calibri]However it doesn't say anything about why this situation could occur[/FONT]
0 Kudos

955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Apr 19 03:20:34 MST 2012
Is it an error or warning...   :)
0 Kudos