Steering wheel remote audio control

Wow, finally got my SWC circuit working.

It uses the MCP2515 CAN bus module, about $2 each on eBay, and a PIC12F1822 (Yes, I know it's an Arduino forum, but the principles are still the same).

The CAN bus talks to the MCP2515 module (which has a CAN transciever) via the 2 way bus; the module talks to the PIC via the SPI bus; and the PIC talks to the Pioneer via PWM as described above.

The tricky bit was finding which CAN bus address was the one that talked to the stereo from the SWC. That was with a lot of fiddling using an ELM327 bluetooth OBDII reader, logging heaps of packets.

But once done, the guts of the main function looked like this in PIC language:

SetFilt(0x20, 0xffffffff); //Sets the mask for BUF0
SetFilt(0x24, 0xffffffff); //Sets the mask for BUF1
SetFilt(0x00, 0x0989726c); //Sets first filter to SWC address
SetFilt(0x04, 0x00000000); //Clears all remaining filters
SetFilt(0x08, 0x00000000);
SetFilt(0x10, 0x00000000);
SetFilt(0x14, 0x00000000);
SetFilt(0x18, 0x00000000);
BitMod(CANINTE,0x01,0x01); //Enable RX0IF interrupt output
//Only needed for debugging
SPI_Mode(LIST); //Listen only

EPWM_LoadDutyValue(167); //Set PWM to idle state (3.3V on 0-5V 8 bit)

while (1)
{
WriteReg (EFLG, 0x00); //Clear any errors
if (ReadStat()&0x01) // If the filter has a match
{
data = ReadReg (0x6d) & 0x0f; //Read the relevant byte out of the buffer
//In this case, it is only the lower nibble
switch (data) // For each case, change the PWM to the corresponding function
{
case 0x0d: // Track fwd
{
EPWM_LoadDutyValue(80);
break;
}
case 0x0e: // Track rev
{
EPWM_LoadDutyValue(94);
break;
}
case 0x07: //Vol +
{
EPWM_LoadDutyValue(110);
break;
}
case 0x0b: // Vol -
{
EPWM_LoadDutyValue(126);
break;
}
default:
{
EPWM_LoadDutyValue(167); //Idle state
break;
}
}
BitMod(CANINTF,0x01,0x00); // Reset the interrupt flag
}
}