livebox:hah_microcontroller

This is an old revision of the document!


Microcontroller firmware

The microcontroller firmware for the AVR is written in C using the Arduino IDE. Firmware revisions before v3.x where written in BASCOM.

The AVR firmware runs a simple text command line interface as its protocol. Connecting directly to its firmware, we can interact directly with the unit. This made writing and debugging the unit easier as all communication is text based and via the Livebox serial port.

We communicate at 115200 baud as this is the default speed for the Livebox serial interface. This also affects the XTAL we need to choose for the hardware. 7.3728Mhz gives us the most accuracy at this baud rate.

The HAH firmware normally runs a process named xap-livebox to connect to the HAH PCB. If you want to connect manually for debug, be sire to kill off the xap-livebox process first. # killall xap-livebox

# microcom -s 115200 /dev/ttyS0
+++         <--- depending on the state of the AVR you might need to jump it past the BOOT wait stage
debug       <--- enter this note it will not be echo'd
>help
$Revision: 271 $  Available Commands:
<relay> = 1-4
  DEBUG
  VERSION
  HELP
  REPORT [1WIRE|PPE|INPUT]
  1WIRE [RESET|DISABLE]
  STATUS [1WIRE|RELAY|INPUT]
  REBOOT
  ON <relay>
  OFF <relay>
  LCD <message>
  I2C SCAN
  I2C R
      Maa   - addr
      Baavv - addr/value
      Paapv - addr/port/value
  URF hex
>

Channels 1-4 map to the internal relays with 5-8 mapping to external RF 'mains socket' relays.

Display the current state of the INPUTS and any devices on the I2C or 1-Wire bus - Debugging command.

>report
input 60,0
1wire 1 20
>

During normal operation these values will be emitted when a change occurs. They are polled by the AVR, using an interrupt, every second.

1wire DEVICE-ID VALUE

To the input value, PORTD of the AVR, the following bit mask 00111100 is applied as only ports 2,3,4,5 are being used to give us our 4x input channels. There is a small debounce applied by the AVR code when reading the inputs. If your environment is 'noisy' you might want to add a small, external, pullup resistor to the input.

input 60,0  (in binary 111100,000000  - VALUE,Change Mask )

As the change mask is 0 no bit has been modified from the previous POLL. The inputs float high with a path to GND(0) when “CLOSED”.

The I2C bus will report the following when a delta is detected between the current and previous value or the report command is issued and an I2C device has been configured.

i2c-ppe ADDR PREVIOUS-VALUE CURRENT-VALUE

The 1-Wire bus is only scanned once during micro-controller startup, if additional devices are added to the unit whilst HOT the bus must be reset to pick these up. We don't recommend hot plugging. Note that the 1-Wire devices always enumerate in the same order. However, if you add a new device, you might find that it takes the slot currently allocated to an existing device. Do check your configuration after adding a new device.

Reset the microcontroller. This will be executed when the Livebox is asked to reboot so both sub-systems stay synchronized.

Toggle a relay or RF relay from the on to the off state.

>on 1
>off 1

Send a message to the LCD screen

>lcd hello world

This command specifies the format of the RF pulse streams that are used to turn RF devices on and off.

  • rf <chnl><on/off><6 bytes in HEX >
  • rf ccpbbbbbbbbbbbb - cc HEX Channel, p On/Off indicator, bbb.. RF control

The on/off indicators mark if this RF sequence turns on or off an external RF device.

Example: The default for Channel 9 (RF05) OFF. Don't forget the 1st four channels are for the internal relays, so RF-1 maps to Channel 5.

  rf 0504D2AAAAAAA80

Technical details

The RF command consists of 6 bytes/48 bits. Of those only 42 bits are used for generating the RF command signal for the Lidl RF sockets.

Looking at one of the RF sequences contained in the /etc/xap-livebox.ini configuration file.

rf1.off=4D2AAAAAAA80

This decodes into the following, we have separated off the last 6 bits as these aren't used.

10011010010101010101010101010101010101010 000000

The transmissions always begin by sending a HIGH pulse and alternates as we read each bit. The length of the pulse is determined by the “value of the bit” + 1, reading the pulse command from left to right.

The break between all pulses is 680uS.

  • 1st bit is 1 so we send two high pulses separated by a 680uS wait.
  • 2nd bit is 0 so we send one low pulse followed by a 680uS wait.
  • 3rd bit is 0 so we send one high pulse followed by 680uS wait.
  • 4th bit is 1 so we send two low pulses separated by a 680uS wait.
  • this sequence carries on.

When an RF signal is transmitted the entire Command is transmitted 8 times with an 80ms break between transmissions.

During transmission, due to the strict timing requirements, the I2C and 1-Wire bus will not be polled.

The BBSB and HomeEasy sockets use a different protocol. Currently we supply an AVR device that is dedicated to either the Lidl OR the BBSB/HomeEasy units.

You can use this application to generate the HE/BBSB .ini file entries bbsbgen.zip

  • livebox/hah_microcontroller.1324251192.txt.gz
  • Last modified: 2011/12/18 23:33
  • by brett