I2C CAN Module.. CAN wont init

I have used two NEW I2C CAN modules,

CAN I2C Module

correctly wired and received at least for a while data from the CAN bus. Over a few hours or less the module stops responding and hangs on this init piece of code. I am in development farther down past this startup() code so I am constantly uploading and testing.

 while (CAN_OK != CAN.begin(CAN_500KBPS)) 

Green power/indicator blinks twice every 1 second, and the bus RCV led is blinking.
This is very frustrating.

Any help would be MUCH appreciated

Scott

This seems to be an initialization problem. Does it work for a while when the program hangs and the code is re-uploaded? And then hang it up again almost an hour later?

Yes - If I pull out of a static bag a brand new part and program it once, I am able to init, jump on the bus and grab information from the CAN devices. If I continue with multiple iterations and re-program the part multiple times, the part dies like I described above. Super frustrating. Ant help or leads to solve this problem is much appreciated.

Scott

I am actually not program the part. I am using the stock firmware that came with the module. I am programming an Arduino and using the class and function calls like CAN.begin etc… over I2C to control the module and poll CAN bus for information. Hope this explanation helps.

Can’t tell if it’s your code problem or our library’s bug, I need time to test it, can you provide your complete code?

#include <P1AM.h> // Main PLC header file

#include “Longan_I2C_CAN_Arduino.h”

#include <Wire.h>

I2C_CAN CAN(0x25);// I2C Address of module

unsigned char flagRecv = 0;

unsigned char len = 128;// Was 0

unsigned char buf[8];

char str[20];

// put your main code here, to run repeatedly:

//unsigned char len = 4; // Was 0 I need 8 to make sometgin work

//unsigned char buf[8]; // was 8

unsigned char what[3]={0x07, 0X01, 0X05};

//unsigned char req[1]={0x502}

//unsigned long batSOC = 0X105;

unsigned long batID = 0X70;

unsigned long hostBatReq = 0x502; // HOST_batteryRequest

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

while(!Serial){

}

delay(1000);

Serial.println(“Serial Set up Complete”);

delay(250);

Serial.println(“Can Init”);

while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k

{

Serial.println("CAN BUS FAIL!");

delay(100);

}

Serial.println(“CAN BUS OK!”);

pinMode(13, OUTPUT); // Where did this come from?

//TOD0 Set mask swe only get BATSOC and error code

}

void loop() {

//CAN.sendMsgBuf(batID,0,1,req);

if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming

{

    CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

    if(len)

    {

      unsigned long canId = CAN.getCanId();

      Serial.print("Get ID: ");

      Serial.println(canId, HEX);

        for(int i = 0; i<len; i++)    // print the data

        {

            Serial.print(buf[i], HEX);

            Serial.print("\t");

        }

        Serial.println("..");

   }

}

delay(250);

blink();

}

void blink()

{

static unsigned long timer_s = millis();

if(millis()-timer_s < 100)return;

timer_s = millis();

digitalWrite(13, 1-digitalRead(13));

}

Thank you for your reply, can you tell me all the hardware equipment you use, I will apply for the same equipment as yours for testing as soon as possible to see if your problem can be reproduced.

Thanks for the help - I did not notice I had a small hardwire issue, and bricked the modules.
I plugged in a NEW module directly to the GPIO module, bypassing my development PCB. I am able to INIT and RECV data from the bus- Thanks for the help!

Scott

begin to init can
CAN BUS OK!
Get ID: 1C10000
1E F0
Get ID: 1C10000

1 Like