I2c can bus modules wont' receive data

Well, this time it seemed to be easy but… it wasn’t !

I’ve bought:

Then I’ve loaded on the first wio the sketch SEND.INO (https://github.com/Longan-Labs/I2C_CAN_Arduino/tree/main/examples/send) and on the other RECV.INO (https://github.com/Longan-Labs/I2C_CAN_Arduino/tree/main/examples/recv)

Both P1 terminal on modules (120ohm termination) are shortened.

The receiver doesn’t receive any data, in particural the call to if(CAN_MSGAVAIL == CAN.checkReceive()) always return “no data available”.

I’m enclosing a picture but the setup it’s very easy, only CANH and CANL connected.

Did someone tried these samples ?
Thanks

Max

First, you need to confirm whether the wiring is correct: CAN_L needs to be connected to CAN_L, and CAN_H needs to be connected to CAN_H. After confirming that there is no problem with the wiring, I suggest you use the Arduino board to test whether it can communicate, because the example you gave seems to use Arduino as the carrier. If the Arduino can’t run, maybe there is a problem with the CAN bus. If the Arduino can run but the Wio Terminal can’t, it might be a code compatibility problem.

Hi Citric, I confirm that CAN is correctly connected, you can also see it zooming in the picture.

At the moment I don’t have an arduino but I tried using a PC and a usb2can interface (https://www.fischl.de/usbtin/).

The result is the same, i2c module trasmits well but doesn’t receive from PC (I mean always using the provided example REVC.INO)

I guess there’s a problem on the i2c to canbus modules, btw I’ve bought 5 pieces and all of them gave the same result.

Thanks

Well, I’ve found a solution thanks to this video (https://www.youtube.com/watch?v=h-NMovSLySQ&ab_channel=RoelVandePaar)

I’m pretty sure this behaviour is given by Wio Terminal speed (120mhz) and maybe you don’t have this problem on other platforms.

I had to edit the Longan Labs library file “Longan_I2C_CAN_Arduino.cpp” in two overrided methods :

*bool I2C_CAN::IIC_CAN_GetReg(unsigned char __reg, int len, unsigned char __dta)
and
*bool I2C_CAN::IIC_CAN_GetReg(unsigned char __reg, unsigned char __dta)

adding a little delay between endTransmission and requestFrom in both methods like this:

Wire.endTransmission();
delay(1);   // THE FIX 
Wire.requestFrom(IIC_ADDR, len);

The one with 2 parameters is called by byte I2C_CAN::checkReceive(void) method and it won’t work if you don’t put a little delay here :

Now the receiver (finally !!!) works

Three last notes:

1 - the video’s author suggests to use a smaller delay, but I’ve wasted so much time that delay(1) it’s ok with me.
2 - Pay attention to library updates ! they could reset your editing
3 - I’d like manufacturer to better test their code before releasing…

1 Like