Hello everyone
I am trying to work with CANBus on an Electron board, but in my case I am using pins C4 and C5, can someone tell me if I am correctly implementing the code?
This is the code:
CANChannel can(CAN_C4_C5);
SYSTEM_MODE(MANUAL);
void setup() {
can.begin(125000); // pick the baud rate for your network
}
void loop() {
CANMessage Message;
Message.id = 0x100;
Message.len = 1;
can.transmit(Message);
delay(10);
if(can.receive(Message)) {
Serial.println(Message.id);
Serial.println(Message.len);
}
}
I tried your code in the web IDE and it failed to compile. I tried it again on my desktop with Particle Workbench and it compiled just fine. Your code is good. The web IDE may not be selecting the Electron as the build target.
@staysayo
Thanks for answering
In the Web IDE I can compile I have no problems, when I send the code to my Electron board and try to see through the serial port that my Electron board receives information by CANBus does not print anything, that’s why I doubt that the code was good .
I am trying to communicate with an Orion BMS, Will you have any advice that I am not considering?.
For one, you are not calling Serial.begin()
in setup()
.
And in order to know wheter the USB Serial interface works at all, having some print statements that don’t rely on uncertain conditions should at least help remove any doubt about the interface being initialised.
2 Likes
@ScruffR I solved the problem, the problem was not the call of Serial.begin ()
in setup ().
The problem was the baud rate, if someone else serves the comment, they must check what baud rate has the Bus to which they want to connect.
@ScruffR and @staysayo thanks for answering