Hi all.
My name is Tiago, i'm portuguese but currently living in the UK.
I have a background of electronics from 10 years ago in school, TTL logic, transistors, resistors etc. but no programming experience, but i'm a fast learner.
My interest in electronics have recently reapeared and wanting to do some cool projects, after a lot of reading on the current state of things i thought the Arduino would be the best for me.
My project now is:
Mercedes Steering Wheel CANBUS Decoder
Objective: Decode the buttons pressed (VOL+, VOL-, NEXT, PREV, PICKUP, HANG-UP) on the steering wheel of the car to control an aftermarket stereo.
CAR - Mercedes E class (facelift) W210, buttons are sent on the interior CAN (CAN-B) wich runs at 83.3kbs.
Radio - Chinese branded navi unit with resistor dependant button presses.
Hardware - Arduino UNO SMD (DFRDuino) from DFRobot and CANBUS Shield from SKPang.
Phase 1 - read all messages on CANBUS and determine button PID and data (6 buttons), basicaly a CAN SNIFFER and send thru serial to the computer.
Example from Mercedes CLK350 2007 - Source: Howard Honig @ CAN BUS Interface to a Mercedes Benz CLK350
Steering Wheel Buttons PID 1A8 - 2 BYTES (BYTE 0 determines button, BYTE 1 not used - always 0)
FUNCTION | BYTE0 | BYTE1 |
---|---|---|
HANG-UP | 80 | 0 |
PICKUP | 40 | 0 |
VOL- | 20 | 0 |
VOL+ | 10 | 0 |
NEXT | 02 | 0 |
PREV | 01 | 0 |
Phase 2 - set MCP2515 to only accept the PIDs that relate to the buttons.
Phase 3 - Control a digital potentiometer so that each button means a certain resistance.
Phase 4 - Standalone PCB with the ATMega chip from the Arduino and the MCP2515 to install permanently in the car.
THIS IS PHASE 1
This is the code i have so far, i now that there are some libraries out there to control the SKpang shield but I thought about doing it all "by hand" to be able to learn some more.
This code compiles. What i need to know is, is this the correct procedure to initiate the MCP2515? From reading the MCP2515 datasheet and those other libraries (from DaveAK, SKPang, etc.) i think this is correct.
And if so is the next step just to start reading messages from the BUS? Or do i have to do something else before? I'm starting to get a bit lost in the datasheet.
#include <SPI.h>
int CS_PIN = 10;
int INT_PIN = 2;
void setup()
{
pinMode(CS_PIN, OUTPUT); //MCP2515 Chip Select PIN on the SKPang shield
pinMode(INT_PIN, INPUT); //MCP2515 INTERRUPT PIN on the SKPang shield
Serial.begin(115200); // Start serial comunication to send data to computer.
// SPI comunication configuration
SPI.setClockDivider(SPI_CLOCK_DIV2); // setClockDivider divide by 2 since MCP2515 runs its SPI at 10Mhz.
SPI.setDataMode(SPI_MODE0); // DataMode 0 (0,0) or 3 (1,1) are the only ones to use with the MCP2515
SPI.setBitOrder(MSBFIRST); // MSB as used by the MCP2515
SPI.begin();
// Initiate MCP2515 and set to LISTEN-ONLY mode.
digitalWrite(CS_PIN, LOW);
SPI.transfer(0xC0); //RESET
// Bit timing Data, calculated using "MBTime" from Intrepid Control Systems for a Oscilator value of 16Mhz used by the MCP2515 and 83.3kbs used by Mercedes for the CANBUS
SPI.transfer(0x2A); //CNF1
SPI.transfer(0x07); // Data
delay(10);
SPI.transfer(0x29); //CNF2
SPI.transfer(0xA8); // Data
delay(10);
SPI.transfer(0x28); //CNF3
SPI.transfer(0x03); // Data
delay(10);
SPI.transfer(0x2B);
SPI.transfer(255); // CANINTE, all interrupts active, used later to tell Arduino that a valid message as been received
delay(10);
// Set LISTEN-ONLY mode thru BITMODIFY
SPI.transfer(0x0F); // CANCTRL
SPI.transfer(B11100000); // Send mask
SPI.transfer(0x60); // Send mode
digitalWrite(CS_PIN, HIGH);
}
void loop()
{
}
Sorry in advance for the long post and for any gramar errors, english is not my first language.
Hope to learn alot from you guys, Arduino is really a good tool to get started, easy to learn and intuitive.
Best regards
Tiago Amarante