Teensy In-Built CAN: struggling with basics

Status
Not open for further replies.

Gilbo

New member
First post on PJRC - I've used some PJRC libraries for a while and they've been excellent, including the encoder library. Now moving some projects to the Teensy hardware.

With regards Can Bus, I've got off to a good start using a standard Uno and Can breakout, and employing the mcp-CAN.h library ( https://github.com/coryjfowler/MCP_CAN_lib ). I've successfully "hacked" my VAG group HVAC controller, and can control and receive the required messages for climate control.

All good, but now I would like to transfer the solution to Teensy-based hardware, being attracted to the built-in CAN functionality and the Teensy microcontrollers for their size and performance.

I've under-estimated this solution "port" from mcp-CAN.h to the "FlexCAN" library. It has presented itself as a real "bag of worms", with multiple forks of FlexCAN(at least 4) on Github born from functional issues. The examples sketches are vague for a novice such as myself (and sometimes tied to specific h/w such as dual-can Teensy 3.6 platforms), and this is where the original mcp CAN scored: nice clear examples of both send, and receive. Working in minutes. All confidence boosting and typical of the simple, "any idiot can do it" Arduino world (based on taking working examples and adapting).

I know I should invest in a deeper-dive of the FlexCAN library such that I will be rewarded with better knowledge for a better implementation. Time is precious however, and in this instance, the "simple solution that works with a clear consistent set of examples" would well for myself. Scanning the forum, I can detect a level of inconsistency, and frustration in which FlexCAN to use?

To illustrate how badly I'm performing, I cannot do a basic send of a Can message (ID 0x271 with subsequent data ) to tell the car controllers that ignition is On. Without ignition On, the module is asleep and sends nothing back. When it works, everything comes to life and the fun decoding starts. To date, I cannot get past this fundamental stage. My equivalent Mcp-Can sketch: (basic send ignition ON)


***************************
#include <mcp_can.h>
#include <SPI.h>

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128]; // Array to store serial string

#define CAN0_INT 2 // Set INT to pin 2
MCP_CAN CAN0(10); // Set CS to pin 10


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

// Initialize MCP2515 running at 8MHz with a baudrate of 100kb/s and the masks and filters disabled.
if(CAN0.begin(MCP_ANY, CAN_100KBPS, MCP_8MHZ) == CAN_OK)
Serial.println("MCP2515 Initialized Successfully!");
else
Serial.println("Error Initializing MCP2515...");

CAN0.setMode(MCP_NORMAL); // Set operation mode to normal so the MCP2515 sends acks to received data.

pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input


// ignition codes: based on 0x271 ignition, 1 byte, message approx. Every 100ms

// 0x10: vehicle unlocked, key not stuck
// 0x11: vehicle unlocked, key inserted in pos. 0, ignition off
// 0x01: vehicle unlocked, key inserted in pos. 1, ignition off
// 0x05: vehicle unlocked, key in pos. 2, ignition off
// 0x07: vehicle unlocked, key inserted in pos. 3, ignition on
// 0x0B: vehicle unlocked, key inserted in pos. 4, ignition on, starter on
// 0x87: vehicle unlocked, key inserted in pos. 3, ignition on, engine running

byte ignOFF[1] ={0x11};
byte ignON[1] ={0x07};
byte ignRUN[1] ={0x87};


}

void loop()
{

// ******* CAN-BUS ON PULSE TO REPLICATE IGNITION ON IN TEST *************
// send data: ID = 0x271, Standard CAN Frame, Data length = 1 bytes, 'data' = array of data bytes to send
byte sndStat = CAN0.sendMsgBuf(0x271, 0, 1, ignRUN);
if(sndStat == CAN_OK){
// Serial.println("Message Sent Successfully!");
} else {
// Serial.println("Error Sending Message...");
}
//delay(100); // send data per 100ms
// ****** END OF CAN-BUS IGNITION FOR TEST

******************************

So to my questions:
1) FlexCAN: is there more on the library(s) in terms of help and examples than available on the readme files and examples on GitHub?
2) Is FlexCAN clear and simple for everyone else?
3) Any good working examples out there? Especially that would allow me to convert the elements above for sending the ignition-on message.

For information, I've got Can transceiver boards for Teensy from SK Pang, and the dual channel example from Tindie for the 3.6. I've got Teensy models 3.2, 3.5, and 3.6.

Sorry if I've missed some etiquette on my first post, but any pointers in the right direction would be most appreciated.

Thanks!
 
Thanks for the suggestion and quick response. I’m travelling at the moment, but keen to make progress (in my head leastways), so a couple of questions:
1) reading your thread on the forum, an earlier post suggests a level of sketch portability between MCP-Can and IFCT, is this the case today and is it a good option?
2) if yes to above, where I can essentially “drop in” my MCP sketch, which library to I include?

Thanks again for your response. Teensy I think is a great platform, but I’ve been tearing my hair out with its implementation of Can at novice level...
 
it’s an emulation of mcpcan that uses similar commands but forwards then to the teensy driver api interface
you dont need to rely on mcp code just use IFCT directly its very user friendly, many examples included.

Once you check out the examples you will understand how very easy it is to receive and send :)
 
Status
Not open for further replies.
Back
Top