Hi Sutton
> In the 'C' code, it appears that all the manipulation is done
> to the SDA and SCL lines directly.
The example is very probably a bit-banging example for any chip,
even without an IIC controller. Of course you can also bit bang on
any port which can be configured as input and output - therefore the
code will even run.
If you want to use the IIC controller in the LPC then it will only
give you some ideas - you can use polling mode [presumably as in the
bit-banging example] or interrupt driven with teh internal IIC
controller.
Here's how to send (defines are hopefully logical) and it is assumed
that the I/O lines are configured for IIC, rather than general
purpose ports - interrupts configured and enabled.
1. I2CONSET = (I2EN + STA); - send start condition
2. On interrupt, read I2STAT, which will read as 0x08. Now send
I2DAT = Address_of_chip; followed by
I2CONCLR = (SIC); // clear the SI bit and continue
3. When the slave sends an ACK to its address, the interrupt routine
is called and I2STAT is 0x18.
I2DAT = ucI2CTxData; // send the first byte of data
I2CONCLR = (SIC + STAC); // clear the SI bit and STA bit
4. Subsequent interrupts have the status 0x28 and the next byte of
data can be sent using the previous sequence, until all data has
been sent, in which case the following code is used:
I2CONCLR = (SIC + STAC); // clear the SI bit and STA bit
I2CONSET = STO; // set stop bit
The transmission has now completed.
There are however a number of details which I haven't described, as
well as the receive case. For example there can be a number of error
interrupts such as a slave not responding and when using multi-
master it can get even more complicated.
Also some devices (possibly yours(?)) need a sequence where they are
first addressed and then a re-start sequence is performed before the
actual data is sent.
Therefore it is best to read through the operation of the controller
and device, including the error conditions and get to know the
protocol in some more detail (if multi-master mode is not required
then just ignore its details since it is much easier then).
Perhaps this has also cleared up the SI use.
Cheers
Mark Butcher
www.mjbc.ch
>
> Another ? I have is that in the user manual, it always says 'When
your
> data has been sent and the acknowledgement has been received, then
> ....', is the ACK the SI bit? Or do I have do anything else
besides
> clear the SI bit to 'get the acknowledgement'? Not clear on
that...
Show quoted textHide quoted text