I have a single CAN device - it outputs CAN H and CAN L. I will never have any other CAN devices connected to the UNO 4 WiFi. Can i input these signals directly into the UNO4 without an external transceiver?
I am now assuming not.
I am realizing that I was getting a bit confused at the Renesas data sheet, which seemed to indicate that CRX0 and CTX0 were on different pins than the UNO 4 documentation and I thought that maybe if i connected to the correct pins i could avoid the transceiver.
I am now noticing that there are actually three sets of pins, P102 and P103, P109 and P110, or P401 and P402 that are labelled CRX0 and CTX0 on the Renesas.
P109 and P110 are used in the communication between the ESP and the Renesas, so that is likely why P102 and P103 are in use.
Any thoughts on what it would take to set up P401 and P402 instead in the code if i was using a custom layout? Those pins may be more readily available.
you require a CAN transceiver such as the cjmcu-1051
this works on the UNO R4 WiFi OK
// UNO R4 WiFi CANBUS transmit/receive
// adapted from File>Examples>Arduino_CAN>CANread and CANwrite
/*
See the full documentation here:
https://docs.arduino.cc/tutorials/uno-r4-wifi/can
*/
#include <Arduino_CAN.h>
static uint32_t const CAN_ID = 0x20;
void setup() {
Serial.begin(115200);
delay(2000);
while (!Serial) {}
Serial.println("UNO R4 WiFi Canbus transmit/receive");
// initialise CAN interface
if (!CAN.begin(CanBitRate::BR_125k)) {
Serial.println("CAN.begin(...) failed.");
for (;;) {}
}
Serial.println("Canbus setup on D10 and D13");
}
static uint32_t msg_cnt = 0;
void loop() {
// if keyboard hit transmit a message
if (Serial.available()) {
// Assemble a CAN message with the format of
// 0xCA 0xFE 0x00 0x00 [4 byte message counter]
uint8_t const msg_data[] = { 0xCA, 0xFE, 0, 0, 0, 0, 0, 0 };
memcpy((void *)(msg_data + 4), &msg_cnt, sizeof(msg_cnt));
CanMsg const msg(CanStandardId(CAN_ID), sizeof(msg_data), msg_data);
//Transmit the CAN message, capture and display an error core in case of failure.
if (int const rc = CAN.write(msg); rc < 0) {
Serial.print("CAN.write(...) failed with error code ");
Serial.println(rc);
//for (;;) {}
}
Serial.print("CAN transmit ");
Serial.println(msg);
msg_cnt++; /* Increase the message counter. */
while (Serial.available()) Serial.read();
}
// if CAN message received display it
if (CAN.available()) {
Serial.print("CAN receive ");
CanMsg const msg = CAN.read();
Serial.println(msg);
}
}
UNO R4 WiFi serial output
UNO R4 WiFi Canbus transmit/receive
Canbus setup on D10 and D13
CAN transmit [020] (8) : CAFE000000000000
CAN transmit [020] (8) : CAFE000001000000
CAN transmit [020] (8) : CAFE000002000000
CAN receive [200] (8) : 0D4D454741000708
CAN receive [200] (8) : 0E4D454741000708
CAN receive [200] (8) : 0F4D454741000708
CAN receive [200] (8) : 104D454741000708
CAN transmit [020] (8) : CAFE000003000000
CAN transmit [020] (8) : CAFE000004000000
UNO with a MCP2515 CAN shield output
CAN MCP2515 shield Send/Receive test - MCP2515 Initialize
Entering Configuration Mode Successful!
Setting Baudrate Successful!
CAN Receive - MCP2515 Initialized Successfully!
MCP2515 Library CAN Send/Receive Example
Standard ID: 0x020 DLC: 8 Data: 0xCA 0xFE 0x00 0x00 0x00 0x00 0x00 0x00
Standard ID: 0x020 DLC: 8 Data: 0xCA 0xFE 0x00 0x00 0x01 0x00 0x00 0x00
Standard ID: 0x020 DLC: 8 Data: 0xCA 0xFE 0x00 0x00 0x02 0x00 0x00 0x00
0x0D 0x4D 0x45 0x47 0x41 0x00 0x07 0x08 Message Sent Successfully!
0x0E 0x4D 0x45 0x47 0x41 0x00 0x07 0x08 Message Sent Successfully!
0x0F 0x4D 0x45 0x47 0x41 0x00 0x07 0x08 Message Sent Successfully!
0x10 0x4D 0x45 0x47 0x41 0x00 0x07 0x08 Message Sent Successfully!
Standard ID: 0x020 DLC: 8 Data: 0xCA 0xFE 0x00 0x00 0x03 0x00 0x00 0x00
Standard ID: 0x020 DLC: 8 Data: 0xCA 0xFE 0x00 0x00 0x04 0x00 0x00 0x00
test setup
The answer is you can connect it but it will not work. Why? CAN messages require an acknowledgement, which needs to be generated by another device it cannot acknowledge its own message.
Your question is ambiguous but if you have a can transceiver on the UNO and your device has one then if setup properly it will work. This works because each device has another to acknowledge it. You must terminate both ends with 120 Ohm resistors.
