SWCAN Library - Anybody have it actually working in car?

I loaded up the SWCAN library from Github. No luck talking to GMLAN.

I get nothing. Zip. Nada.

Here is my slightly modified code from the example:

#include <SPI.h>
#include <MCP2515_sw_can.h>

// Pin definitions specific to how the MCP2515 is wired up.
#define CS_PIN    85
#define INT_PIN    84
#define Serial SerialUSB

// Create CAN object with pins as defined
SWcan CAN(CS_PIN, INT_PIN);

void CANHandler() {
	CAN.intHandler();
}

void setup() {
	Serial.begin(115200);

  //while (!Serial);

  pinMode(DS2, OUTPUT);
  pinMode(DS6, OUTPUT);
  
	Serial.println("Initializing ...");

  digitalWrite(DS2, HIGH);

	// Set up SPI Communication
	// dataMode can be SPI_MODE0 or SPI_MODE3 only for MCP2515
	SPI.setClockDivider(SPI_CLOCK_DIV2);
	SPI.setDataMode(SPI_MODE0);
	SPI.setBitOrder(MSBFIRST);
	SPI.begin();
	
	// Initialize MCP2515 CAN controller at the specified speed and clock frequency
	// (Note:  This is the oscillator attached to the MCP2515, not the Arduino oscillator)
	//speed in KHz, clock in MHz
	CAN.setupSW(33);
  CAN.mode(0x03);
	
	attachInterrupt(6, CANHandler, FALLING);
	CAN.InitFilters(true);
	//CAN.SetRXMask(MASK0, 0x7F0, 0); //match all but bottom four bits
	//CAN.SetRXFilter(FILTER0, 0x100, 0); //allows 0x100 - 0x10F
	//So, this code will only accept frames with ID of 0x100 - 0x10F. All other frames
	//will be ignored.

	Serial.println("Ready ...");
  
}

byte i=0;

// CAN message frame (actually just the parts that are exposed by the MCP2515 RX/TX buffers)
Frame message;

void loop() {	
	if (CAN.GetRXFrame(message)) {
    digitalWrite(DS6, HIGH);

		// Print message
		Serial.print("ID: ");
		Serial.println(message.id,HEX);
		Serial.print("Extended: ");
		if(message.extended) {
			Serial.println("Yes");
		} else {
			Serial.println("No");
		}
		Serial.print("Length: ");
		Serial.println(message.length,DEC);
		for(i=0;i<message.length;i++) {
			Serial.print(message.data.byte[i],HEX);
			Serial.print(" ");
		}
		Serial.println();
		Serial.println();
    digitalWrite(DS6, LOW);

	}
}

Collin was the creator of this code and I believe he recently mentioned it doesn’t work well and needs a total rewrite.

I could be wrong.

Rodney

I think you are referring this this comment which was resolved by Macchina/mcp2515 #9 and is included with the latest Macchina boards package.

I have tested the SWCAN support to work now. But, I did it with two USB capture devices - A Macchina M2 connected to an EVTV CANDue 2.2. Doing so allowed me to send traffic from the M2 and receive it on the CANDUE. But, that’s as far as I’ve tested. So, that’s a promising start but I can’t say I’ve tried it in a car yet. It may or may not be good enough yet. I should be doing testing this weekend with an SWCAN device to see how it works.

I think I have it figured out, I’ll chuck in into the car tomorrow and see if I get something.

If I do I’ll post up a gist…

So the current libraries are pointed to in the documentation here now? I can install it in mine and test later today once I have my hands on the proper version.

If you mean this list, yes; those hyper-links take you to the correct libraries at a version that is compatible with M2RET.

SWCAN_test_m2 - Working and tested code in a 2009 Cadillac CTS.

Working. Changes from the included example:
SPI CS and INT pins need to be set correctly.
CAN.mode needs to be set to normal. Note that this isn’t CAN.Mode which corresponds to the MCP2515 mode.
Removed the transmit section and packet filters - transmitting on the GMLAN bus can cause bad things to happen.

Enjoy your weekend.

Why is it bad to transmit on the SWCAN? I also have a 2009 CTS so should see similar results. Is your posting a fix of collins?

Havent looked yet but did download

It’s mostly fixes. The example does not have the right pins for CS and INT. Didn’t put the SW Can transceiver into normal mode. I’d imagine the the MCU powers up with those 2 pins low, and therefore the SWCAN transceiver is sleeping…

Transmitting should be fine if you know what you are doing. I have had to pull the battery to reset all the modules when things go wrong. Just be careful. It’s your car after all. Expensive to reflash modules.

So I have the libraries that are linked to the forum.

How did you apply your file to get it working?

I am still new to Arduino so I am not sure what to do with your file. Does it replace one of the current files or how do you us it?

Are we just running the test code instead of the M2RET stuff?

Reset the battery to clear stuff because you transmitted something “wrong” on SWCAN with a GM vehicle?

Im calling BS on that one, sorry. I have easily a thousand hours into reverse engineering high speed GMLAN and low speed GMLAN (SWCAN). Ive done some wicked crazy stuff on the bus and never once “bricked” anything or done something that required a power cycle…

Well… You can write to memory on a module via SWCAN. You can write DIDs back to modules via SWCAN. I have done both.

I have gotten an Infotainment system in a Pontiac G8 to not recognize onstar via SWCAN spoofing. Needed a power cycle/battery disconnect reconnect to get it back.

So - just be careful out there. A tow truck and a reflash at the dealer is a couple of hundred bucks. Better to error on the side of caution.

mehhh thats because the G8 is a Holden, the Aussie’s did lots of oddball crap on them lol

You really cant mess up any of the other GM common-architecture-1 vehicle like that.

Common-arch vehicles include:

06-13 impala
08+ express van
07-14 silverado/sierra/tahoe/suburban
06-12 caddy dts
08-13 caddy cts
08-09 G8
07-16 acadia/traverse/enclave
07-09 equinox
some year malibus, buicks, and monte-carlos, I dont know which years off the top of my head

And then a couple other oddball vehicles that you probably wouldnt ever come across…suzuki XL7 (well thats basically an equinox), 08-16 captiva, 08-11 saturn vue, etc

The only CA-1 modules with easily configurable/writable DID’s are the BCM (VIN, brake pedal position, SDM primary key), RPA (VIN), RCDLR (TPMS warning thresholds), radio (VIN). Yes, every other module can have its software/cal reflashed…but that would involve probably 1000+ hours of Arduino code writing, reverse engineering the GM seed/key algo, and you’d need all the factory original software bins to start with.

If you really want to/need to reflash GM modules, buy a chinese knock-off MDI ($160), a 3-day subscription to AC Delco TIS ($50), and do it the easy way, like dealer techs do.

Re-writing the VIN on the BCM also requires security access (seed/key). So even if you were to figure out how to gain security access on the BCM and changed the VIN…your radio and park assist module would temporarily disable themselves until you changed the VIN back.

Even if you re-write/change the VIN on a CA-1 BCM, no big deal…contrary to popular belief, the VIN doesnt have anything to do with the immobilizer on CA-1 vehicles. The BCM doesnt even have anything to do with immo. Its only between the TDM (theft deterrent module) and ECM. Well, the BCM is the middle-man because TDM is only on SWCAN and ECM is only on high speed CAN.

I could literally take the BCM out of an 08 caddy CTS, plug it into my 2012 Sierra, and the thing would start and run. Half the lighting and door locks and stuff probably wouldnt work because the hardware I/O’s on the Caddy BCM cal would be mapped incorrectly for a sierra wiring harness, but CA-1 vehicles really are NOT picky. Hell, an 06 caddy DTS uses the exact same BCM as a 2018 express van, just a different software cal.

Moral of the story, no beginner here is going to “fat-finger” the wrong SWCAN command/message and break anything…writing DID’s and gaining security access is pretty advanced stuff to the point that I dont think 99% of people here have to be “scared” of it. :slightly_smiling_face:

Ben