User manual

LPCXpresso Experiment Kit - User’s Guide
Page 97
Copyright 2013 © Embedded Artists AB
*****************************************************************************/
void main (void)
{
/* initialize I2C as needed */
I2CInit( I2CMASTER, 0 );
/* enter forever loop */
while(1)
{
/* read temperature and print result */
...
/* wait 3 seconds */
...
}
}
Place the LM75 related code in file lm75.c.
7.14.3 Lab 13c: Control LEDs via PCA9532
In this experiment a GPIO expansion chip, PCA9532, shall be used. The chip can also generate PWM
waveforms to for example dim LEDs. It is essential to study the PCA9532 datasheet before writing any
code. The PCA9532 chip has a more complex interface than the LM75. More registers must be
controlled. There are 16 I/O pins and 10 registers in the chip:
Two registers are used for reading the 16 inputs (two bytes).
There are two PWM generators in the chip. Two registers are needed to control each
generator, so four registers in total for this.
Four registers are used to control the 16 pins if they are outputs. 2 bits per pin, which means
that one byte can control 4 pins resulting in four registers to control 16 pins. A pin can have
one of the following four states:
o Actively driven low.
o High impedance where the pin is typically driven high by an external pullup resistor.
The pin can also be an input in this state.
o Driven by PWM generator #0, alternating between actively driven low and high-
impedance.
o Driven by PWM generator #1.
The external LEDs are connected via the cathode to the PCA9532 chip. This is because the chip can
only sink current.
Below is a code framework for controlling the 16 outputs via function pca9532_setLeds(...).
#define PCA9532_I2C_ADDR 0xC0
#define PCA9532_INPUT0 0x00
#define PCA9532_INPUT1 0x01
#define PCA9532_PSC0 0x02
#define PCA9532_PWM0 0x03
#define PCA9532_PSC1 0x04
#define PCA9532_PWM1 0x05
#define PCA9532_LS0 0x06
#define PCA9532_LS1 0x07
#define PCA9532_LS2 0x08
#define PCA9532_LS3 0x09
#define PCA9532_AUTO_INC 0x10
/******************************************************************************
* Defines and typedefs
*****************************************************************************/