Brian,
On Tue, 2011-03-01 at 21:49 -0600, Brian Schmalz wrote:
> I've been tasked with adding I2C slave
functionality to a tiny little
> LPC2101 based board. I'm new to ARM, although I'm quite familiar
with
> other 32 bit processors (PIC32, Blackfin, etc.) I'm using Yagarto.
>
> Anybody know of any simple little examples to help me get started?
> I'd rather not have to reinvent the wheel. I see that NXP provides
> some super simple assembly example code in an app note - but I'm
> hoping there's something a bit more polished out there.
For me the best way to get started with i2c was hooking up a pcf8574
to the micro and start writing the master code. This way I could get
the understanding needed on how the i2c bus works and how to write
the i2c interrupt code.
But first off I would like to advice you to get one of these :
http://www.saleae.com/logic/
It works beautifully on Linux ubuntu/debian !
Then there's appnote an10369 from the nxp site.
And do not forget to read the i2c protocol pdf um10204.
First you need to initialize the i2c registers/hardware. Set the scl
frequency to a low value just for debugging. Do not forget about the
aa bit and the IO pin setup.
In the interrupt code you will have a switch/case like this :
void i2c_interrupt_service(void) blahblah
{
switch(i2c0stat)
{
/*
* Miscellaneous state 0x00
*
* Bus error during MST or selected slave modes,
* due to an illegal start or stop condition.
* State 0x00 can also occur when interference
* causes sio1 to enter an undefined state.
*
* Switch to not addressed slave mode.
*/
case 0x00:
....
break;
/*
* MT/MR 0x08
*
* A start condition has been transmitted.
*
* Slave address + write will be transmitted.
*/
case 0x08:
.....
break;
/*
* MT/MR 0x10
*
* A repeated start condition has been transmitted.
*
* Slave address + read will be transmitted;
* or
* Slave address + write will be transmitted.
*/
case 0x10:
....
break;
more case statements.....
}
}
And ofcourse our great friend Google :-)
Search for "i2c bus"; lots of information.
roelof