Monday, September 3, 2007

AVCLan (IEBus) sniffer and device emulator project

Purpose: to be able to simulate different devices attached to the IEBus.

Toyota uses the IEBus standard for internal equipment to communicate. As far as it is almost impossible to buy the IEBus driver IC it is possible to simulate it on a uController. The uController shall be fast enough to process the bus signal impulses that are less then 3 uSec. And at the same time the uController shall be fast enough to send received and processed data to the host computer in less then 120-130 uSec so the next message on the bus is not lost.

The uController of choice is pic18f2550. It contains the USB 2.0 module which supports full speed communication mode and can principally work up to 48MHz. It also contain 2 internal comparators that can be used to receive signal from the bus (though it was decided to use an external comparator to separate the uController from the bus). Device is supported by the PICmicro 18Cxx C compiler so it is possible to write the firmware in C. I'm using compiler version 2.40.

Complete schematic of the emulator is here.

If the board is connected to the host computer and works as sniffer then it can be powered right from the USB. If device works as emulator in the car then it require additional power supply provided by the LM317 regulator. Different oscillators can be used to drive the chip due to onchip prescaler. The prescaler value is adjusted by changing the chip configuration bits when the boot loader is burned. SW2 is used to switch between normal operation and boot loader at device start.

To send messages to the bus the PCA82C250 CAN driver is used. To receive messages this CAN driver cannot be used because IEBus and CAN have little bit different voltage standard.

First of all it is necessary to put the boot loader on the uController to be able to reprogram the chip right in the car without a programmer using only a notebook. Unfortunately it is necessary to have a programmer to burn the boot loader. I used the ICD2 programmer clone with USB connector. The complete project is here Boot Loader

For some reason the uController chip I have didn't work stable at full speed (48MHz). Thats why I've adjusted postscaler in the config bits to work at 32MHz (later I had to use assembler is some cases and some other tricks to improve performance). When the boot loader is on the chip the SW2 shall be pressed at the device start to switch to the boot mode. It is necessary to download the Boot Loader Software from the Microchip site which contains driver for Windows OS and a PDFSUSB.exe program to transfer hex files with the firmware from the host to the uController.

Devices communication protocol is described for example in the uPD72042 datasheet. The most important part of this datasheet is shown here.

Toyota uses Mode 1 at 6MHz for the communication.

Example of a recorded message on the bus is shown here

Start bit is approximately 170 uSec followed by 20uSec low level before the first bit. Logic 1 is represented by 20uSec high level and 20uSec low level. Logic 0 is represented by 33uSec high level and 7uSec low level. More information about communication protocol between devices can be found here Toyota AVC

The USB transfer is based on the USB CDC serial emulation specification. That means that there will be a virtual serial port driver installed and to catch data sent by the board it is just enough to use Terminal software (HyperTerminal on Windows OS for ex.). Details of the USB programming interface in the CDC mode can be found here CDC communication. The following example available on the Microchip site CDC Example also contains a driver (an .inf file) which is needed to register the virtual serial port.

The final goal of the project is to enable aux audio input by simulating a cd changer and to enable aux video input by simulating DVD changer or RSE (rear seat entertainment) system. Currently CD changer simulation works so it is possible to activate the line input on the CD changer harness of the navigation head unit display. Current firmware with the project files are here CD Changer Emulator 001

There are couple of defines inside of the io_cfg.h.

*  DIVIDER defines the chip clock frequency.
*  DIVIDER_0 defines 48Mhz chip clock,
*  and DIVIDER_1 defines 32Mhz chip clock
#define DIVIDER_1     // we use 32Mhz chip clock

*  INPUT_PIN defines the pin were comparator
*  output is connected to. If changed then the
*  init() function shall be updated too to init
*  the pin correctly
#define INPUT_PIN      PORTBbits.RB3

*  OUTPUT_PIN defines the pin which is connected
*  to the CAN driver TXD pin. If changed then the
*  init() function shall be updated too to init
*  the pin correctly
#define OUTPUT_PIN     LATBbits.LATB2

*  Set it to 1 if only sniffing/logging
*  functionality is needed
//#define SNIFF_ONLY

*  Set it to 1 if no sniffing is needed
*  but device simulation


Robert said...

Hi Flux. I am also working on an IEBus Project on my site. Maybe we could collaborate some time.

Anonymous said...

Hi. I wish to make a pair of similar devices. First is sniffer but with USB reading and writing. Second is AVCLan filter with pair of LM393-PCA82C250. Can you advice me can I use the same PIC as your device or I need more perfomance PIC?