Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: I2C on LPC2148

2006-04-20 by rtstofer

--- In lpc2000@yahoogroups.com, "Sutton Mehaffey" <sutton@...> wrote:
>
> I'm back on my I2C problems since I was pulled off the project for a
> month or so.  I'm still having some problems.  The problem I thought
> was I was trying to address a 5V RAM instead of a 3.3V RAM.  I have
> now a couple of ATMEL 256K serial RAM - 2.7V to 5V.  I am still having
> trouble with understanding the status of the I2C bus.  It appears I am
> getting the correct status, but even when the RAM is disconnected.  I
> 'assume' from the status that those come from the I2C bus (LPC) and
> not the RAM chip itself.  How do I know that the RAM has sent back an
> ACK?  Does the new status on the bus indicate that it has?  Here is
> how my code looks based on writing a 0x77 and reading back from an
> arbitrary address (0x01FFF):
> 
> I2C0CONSET = 0x20;    // Issue Start
> (status responds with 0x08)
> I2C0DAT = 0xA1;       // Issue a write command to RAM
> I2C0CONSET = 0x04;    // Set AA bit for ACK
> I2C0CONCLR = 0x28;    // Clear STA and SI flags
> (status responds with 0x18)
> I2C0DAT = 0x1F;       // MSB
> I2C0CONSET = 0x04;    // Set AA bit for ACK
> I2C0CONCLR = 0x08;    // Clear SI flag
> (status responds with 0x28)
> I2C0DAT = 0xFF;       // LSB
> I2C0CONSET = 0x04;    // Set AA bit for ACK
> I2C0CONCLR = 0x08;    // Clear SI flag
> (status responds with 0x28)
> I2C0DAT = 0x77;       // Write Byte of 0x77
> I2C0CONSET = 0x04;    // Set AA bit for ACK
> I2C0CONCLR = 0x08;    // Clear SI flag
> (status responds with 0x28)
> I2C0CONSET = 0x14;    // Issue a STOP
> I2C0CONCLR = 0x08;    // Clear SI flag
> 
> If I follow this with a Read Sequence, I get correct status, but an
> 'A1', which incidentally coincides with the Chip ID + WRI.  Again, the
> 'A1' is read whether or not I have the RAM actually connected.  Any
> ideas on what I am missing?  I am using an Embedded Artists prototype
> board for this code.  It is also not clear to me how I know if each
> step listed above is actually accepted by the RAM chip.  Thanks.
> 
> Sutton
>

That's why I2C code is usually in the form of an interrupt drive state
machine.

philips_aps has posted sample code for the LPC214x but the ideas are
common for all.  Look in the Files section here.

The bad news about I2C is that if at first it doesn't work, nothing
short of a logic analyzer will capture enough data vs time to be able
to troubleshoot it.  Well, maybe a storage scope but only if you can
come up with a trigger just before or just at the start condition.

The good news is that the Philips code is likely to work.  It is very
similar to code I used for a project with the LPC2106.

Richard

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.