livebox:hah_i2c

Introduction

The I2C bus can be used to extend the number of controllable devices that the HAH can access. Using the PCF8574 chip (PPE) an additional 8 I/O pins are available. Times this by up to 16 chips on the I2C bus and you have at your disposal 128 I/O channels; all accessible using the xAP protocol.

The HAH PCB exposes the I2C bus on a set of four pins. See the image below for the pinout detail.

pcb_i2c.jpg

See also http://arduino.cc/forum/index.php?topic=53962.15 for other circuit references

A custom PPE PCB can be purchased from the shop that contains 4 PPE chips giving you 32 I/O control points in a compact format.

From the AVR firmware this is how things are configured - you should be able to trace D6/D7 out and see where they go on the 4 pin header to make sure you have correctly identified SDA/SCL.

Config Sda = Portd.6
Config Scl = Portd.7

// ATMEL ATMEGA8 & 168 / ARDUINO
//
//                  +-\/-+
//            PC6  1|    |28  PC5 (AI 5)
//      (D 0) PD0  2|    |27  PC4 (AI 4)
//      (D 1) PD1  3|    |26  PC3 (AI 3)
//      (D 2) PD2  4|    |25  PC2 (AI 2)
// PWM+ (D 3) PD3  5|    |24  PC1 (AI 1)
//      (D 4) PD4  6|    |23  PC0 (AI 0)
//            VCC  7|    |22  GND
//            GND  8|    |21  AREF
//            PB6  9|    |20  AVCC
//            PB7 10|    |19  PB5 (D 13)
// PWM+ (D 5) PD5 11|    |18  PB4 (D 12)
// PWM+ (D 6) PD6 12|    |17  PB3 (D 11) PWM
//      (D 7) PD7 13|    |16  PB2 (D 10) PWM
//      (D 8) PB0 14|    |15  PB1 (D 9) PWM
//                  +----+

In this example the following definitions can be set up as xAP endpoints. The endpoint number will be dynamically assigned incrementing by 1 from the last hardcoded endpoint defined internally in the adapter.

The section header indicates the type of I2C chip, this allows additional chip types to be added to the definition file.

328 Firmware (2.x - > 3.x)

PPE Addr I2C Address
PCF8574/N PCF8574A
000 0x40 0x70
001 0x42 0x72
010 0x44 0x74
011 0x46 0x76
100 0x48 0x78
101 0x4A 0x7A
110 0x4C 0x7C
111 0x4E 0x7E

M8 Firmware (v1.0) only supports these 4 addresses and does not support the A variant PCF chip.

PPE Addr I2C Address
PCF8574/N
000 0x40
001 0x42
010 0x44
011 0x46

The following segments are taken from the /etc/xap-livebox.ini file.

; All PINS are used together to represent an input / output byte
[ppe1]
address = 0x40
mode = pin

; Each pin is xAP endpoint addressable
[ppe2]
address = 0x42
mode = byte

Although direct control with the AVR isn't necessary, its useful to understand how the underlying commands are being invoked. If you are having problems and want to do some low level debugging with microcom directly talking to the AVR command interface this is what you need to know.

The firmware command “i2c scan” is VERY useful to make sure that the hardware is correctly setup and configured. Issuing this command will perform a scan of ALL I2C addresses from 0x00-0xFF to see what responds. You can only run this with direct microcom connection to the AVR running in DEBUG mode. See also hah_microcontroller

Additional instructions are going to be needed to configure the I2C devices.

  • Add a new I2C device at an address
  • Send an I2C command

Configuration command

Token Description
M Configure selector
XX Hexadecimal address of the PPE chip

Example configuration for the last entry in the .INI configuration file above is shown first.

i2c MXX
i2c M40
i2c M42

We need the configure command to add this address to the list of PPE chips that should be polled and read. Up to 8 of these PPE chips can be supported.

Control command

There will be TWO commands one for operating in BYTE mode the other for PIN mode.

Pin mode will accept 4 characters

Token Description
P Pin mode selector
XX Hexadecimal address of the PPE chip
Y Pin in the Range 0-7
Z State: 1 or 0, on/off
i2c PXXYY
i2c P4000  - PPE chip at 0x40 Pin 0 LOW - ON (Path to ground)
i2c P4071  - PPE chip at 0x40 Pin 7 HIGH - OFF (no path to ground)

Byte mode will also accept four characters

Token Description
B Byte mode selector
XX Hexadecimal address of the PPE chip
YY Hexadecimal value to write to the chip
i2c BXXYY
i2c B4210 - PPE chip at 0x42 write byte 0x10

Driving an endpoint in BYTE mode. The text attribute must be 2 characters wide and only use HEX characters.

xap-header
{
v=12
hop=1
uid=FF00DB00
class=xAPBSC.cmd
target=dbzoo.livebox.Controller:ppe.1
source=acme.test.com
}
output.state.1
{
id=*
state=on
text=00
}

This is an example of an xAP message that will be generated when the STATE of pin 1 on I2C PPE chip at address 0x42 changes. The UID will be system generated as each endpoint is created. The name of the device will be encoded using the address and pin. In the case where all pins are used this trailing component will simply be dropped.

xap-header
{
v=12
hop=1
uid=FF00DB43
class=xAPBSC.info
source=dbzoo.livebox.controller:ppe.2.1
}
output.state
{
state=on
}

To change the state of the output pins the following xAP would be constructed. This would turn ON PIN5 and OFF PIN6 of the chip defined in the xap-livebox.ini section [PPE2]. We use the wildcard character > so that the pattern matching will examine all PINS of the PPE chip, the ID= of the xAP body will indicate which pin we require.

xap-header
{
v=12
hop=1
uid=FF00DB00
class=xAPBSC.cmd
source=acme.my.controller
target=dbzoo.livebox.controller:ppe.2.>
}
output.state.1
{
id=5
state=on
}
output.state.2
{
id=6
state=off
}

Alternative if only a single PIN is being modified, in this example PIN 7 of I2C PPE2 at address 0x42 we can drop the ID and the wildcard match character (>) and direct the message to the endpoint.

xap-header
{
v=12
hop=1
uid=FF00DB00
class=xAPBSC.cmd
source=acme.my.controller
target=dbzoo.livebox.controller:ppe.2.7
}
output.state.1
{
id=*
state=on
}

Addon PPE PCB

The HAH PCB already has a four way I2C connector. In order to make it easy to addon PPE devices, we have designed a small PCB which can connect directly to (and is powered by) the HAH PCB via a 4-way cable. This board can house between 1 and 4 PPE devices. These are socketed to allow easy replacement. Input and outputs for these chips are provided via 16 way IDC connectors. As well as exposing the port pins, the connectors also expose Gnd and +5V. See schematic below.
Port Connector
The PCB has intentionally been kept as small as is possible (to keep fabrication costs low). Jumpers on the PCB (3 jumpers/chip) allow the required I2C address to be selected. The jumpers are placed vertically and connect each of the address pins on the PPE chip to Gnd (shown as black) or 5V (shown as red). See image below for details.

PPE Jumpers

The I2C connection is mounted on the rear of the board. The boards can be daisy-chained to support more I/O capacity (upto four boards - two with PCF8574N and two with PCF8574AN parts). There are pads to allow bus pullup resistors to be fitted to the board. A pair of 10K resistors should be fitted to the last board in the chain.

Each board has a single, centrally located, mounting point.
Populated PCB
Parts for the board are now available for ordering from the shop. Self assembly, so soldering is required. Despite the small size of this board (5cm x 5cm), there are quite a few components to fit. The kit is packaged to allow you to choose how many PPE devices you will add. Base PCB and all parts for one chip (socket/PPE device/3off 3way molex pins/3 jumpers/2×8 molex I/O connector) + termination resistors and connector to main HAH PCB gets you going. Then a separate kit to add another PPE device.

Boards have a connector to allow 'daisy chaining'. You can add upto 4 boards. A whopping 128 xAP addressable I/O pins!

Back side of board



Note that you need to add a couple of wire links to fix a tracking error. Pin 16 of IC1 to pin 4 of I2COUT and pin 8 of IC4 to pin 1 of I2COUT.

  • livebox/hah_i2c.txt
  • Last modified: 2011/12/31 19:31
  • by brett