A working demonstration on how to read GMLAN packets using an mbed and a compatible CAN transceiver such as (and tested with) the CAN-Bus demo board. The SparkFun CAN Shield should also work perfectly too, as should just about every MCP2551-based solution (but this code should be portable to other transceivers). Please note to get this to work, you must tie CAN_L to ground and connect CAN_H to the single wire CAN.

Dependencies:   mbed

GMLAN Sniffer

Introduction

This project makes use of CAN on an LPC1768 to communicate with General Motors GMLAN network via a compatible transceiver. GMLAN is a single wire CAN Bus that operates at 33.333 kbit with 29-bit header packets and is commonly used for transmission of non-critical information between such nodes on automobiles as the following;

  • Dash cluster
  • Entertainment system (head unit)
  • Satellite Navigation (OnStar for example)
  • HVAC controls
  • Immobiliser / alarm / other security systems
  • Door locks and door status
  • Power Windows
  • Interior / exterior lighting
  • Reversing sensors

The list is extensive, for a better idea of what can be done, view the ARBIDs tab on the GMLAN Bible Google Docs spreadsheet (tabs are at the bottom of the page).

Hardware setup

This is just one example of how you can interface with GMLAN using an SKPang CAN-Bus Breakout Board (based around an MCP2551 CAN Transceiver), using these instructions I assembled the following on my trusty prototyping board;

/media/uploads/foxdie/_scaled_mbed-canbus-layout.jpg

(Click to open high resolution version)

Committer:
foxdie
Date:
Thu Dec 06 08:51:04 2012 +0000
Revision:
1:3daf1c9b3315
Parent:
0:f08f63171361
Child:
2:a285b70981c6
Properly presents information however still needs verification on packets being accurate

Who changed what in which revision?

UserRevisionLine numberNew contents of line
foxdie 0:f08f63171361 1 #include "mbed.h"
foxdie 0:f08f63171361 2
foxdie 0:f08f63171361 3 DigitalOut rx_led(LED1);
foxdie 0:f08f63171361 4 DigitalOut tx_led(LED4);
foxdie 0:f08f63171361 5 Serial pc(USBTX, USBRX);
foxdie 0:f08f63171361 6 CAN gmlan(p30, p29);
foxdie 0:f08f63171361 7
foxdie 0:f08f63171361 8 void clearAndHome()
foxdie 0:f08f63171361 9 {
foxdie 0:f08f63171361 10 pc.printf("%c", 27); // ESC
foxdie 0:f08f63171361 11 pc.printf("[2J"); // clear screen
foxdie 0:f08f63171361 12 pc.printf("%c", 27); // ESC
foxdie 0:f08f63171361 13 pc.printf("[H"); // cursor to home
foxdie 0:f08f63171361 14 }
foxdie 0:f08f63171361 15
foxdie 1:3daf1c9b3315 16 void processMessage()
foxdie 1:3daf1c9b3315 17 {
foxdie 1:3daf1c9b3315 18 time_t seconds = time(NULL);
foxdie 1:3daf1c9b3315 19 rx_led = 1;
foxdie 1:3daf1c9b3315 20 CANMessage rxmsg;
foxdie 1:3daf1c9b3315 21 gmlan.read(rxmsg);
foxdie 1:3daf1c9b3315 22 pc.printf("[%10d]\t[%d]\t[0x%08X]\t", seconds, rxmsg.len, rxmsg.id);
foxdie 1:3daf1c9b3315 23 for (unsigned int i = 0; i < rxmsg.len; i++)
foxdie 1:3daf1c9b3315 24 pc.printf("%02X ", rxmsg.data[i]);
foxdie 1:3daf1c9b3315 25 pc.printf("\r\n");
foxdie 1:3daf1c9b3315 26 rx_led = 0;
foxdie 1:3daf1c9b3315 27 }
foxdie 1:3daf1c9b3315 28
foxdie 0:f08f63171361 29 int main() {
foxdie 1:3daf1c9b3315 30 set_time(0);
foxdie 0:f08f63171361 31 pc.baud(115200);
foxdie 1:3daf1c9b3315 32 int baudrate = 33333;
foxdie 1:3daf1c9b3315 33 // CANMessage rxmsg;
foxdie 0:f08f63171361 34
foxdie 0:f08f63171361 35 // Put device in monitor mode - sniff only
foxdie 0:f08f63171361 36 gmlan.monitor(true);
foxdie 0:f08f63171361 37 gmlan.frequency(baudrate);
foxdie 0:f08f63171361 38
foxdie 0:f08f63171361 39 clearAndHome();
foxdie 0:f08f63171361 40 pc.printf("Starting packet capture at %i bps\r\n", baudrate);
foxdie 0:f08f63171361 41
foxdie 1:3daf1c9b3315 42 gmlan.attach(&processMessage);
foxdie 1:3daf1c9b3315 43
foxdie 0:f08f63171361 44 while(1) {
foxdie 1:3daf1c9b3315 45 wait(0.02);
foxdie 0:f08f63171361 46 }
foxdie 1:3daf1c9b3315 47 // if (gmlan.read(rxmsg)) {
foxdie 1:3daf1c9b3315 48 // rx_led = 0;
foxdie 1:3daf1c9b3315 49 // pc.printf("Message: ");
foxdie 1:3daf1c9b3315 50 // for (unsigned int i = 0; i < rxmsg.len; i++)
foxdie 1:3daf1c9b3315 51 // pc.printf("[%d] 0x%X %02X ", time(NULL), rxmsg.id, rxmsg.data[i]);
foxdie 1:3daf1c9b3315 52 // pc.printf("\r\n");
foxdie 1:3daf1c9b3315 53 // rx_led = 0;
foxdie 1:3daf1c9b3315 54 // }
foxdie 1:3daf1c9b3315 55 // rx_led = 1;
foxdie 1:3daf1c9b3315 56 // }
foxdie 0:f08f63171361 57 }