ESP32 CANBUS Communication #7046
guoquan1963
started this conversation in
General
Replies: 2 comments 5 replies
-
@guoquan1963 The code you have provided doesn't appear to be using any APIs from Espressif but instead a third-party CAN library. I'd suggest talking with the author of the library. |
Beta Was this translation helpful? Give feedback.
5 replies
-
Hello, you may want to see the TWAI (CAN) example: #7430 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Can you tell me how to fix this problem? Any suggestion?
The code for ESP32 is below...
Thanks,
Christie
void setup() {
// put your setup code here, to run once:
Serial.begin(115200, SERIAL_8N1);
delay(1000);
Serial.println("Hello World!");
//-----For CANBUS testing-----
Serial.println("Basic Demo - ESP32-Arduino-CAN");
CAN_cfg.speed = CAN_SPEED_200KBPS; //CAN_SPEED_100KBPS; //CAN_SPEED_250KBPS; //CAN_SPEED_200KBPS; //CAN_SPEED_125KBPS;
CAN_cfg.tx_pin_id = GPIO_NUM_18; //(gpio_num_t)CAN_TX_PIN; //(gpio_num_t)(18); // GPIO_NUM_18; //GPIO_NUM_19; //GPIO_NUM_5;
CAN_cfg.rx_pin_id = GPIO_NUM_5; // (gpio_num_t)CAN_RX_PIN; //(gpio_num_t)(5); // GPIO_NUM_5; //GPIO_NUM_18; //GPIO_NUM_4;
CAN_cfg.rx_queue = xQueueCreate(rx_queue_size, sizeof(CAN_frame_t));
// Init CAN Module
ESP32Can.CANInit();
}
void loop() {
CAN_frame_t rx_frame;
unsigned long currentMillis = millis();
// Receive next CAN frame from queue
if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame, 3 * portTICK_PERIOD_MS) == pdTRUE) {
}
// Send CAN Message
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
CAN_frame_t tx_frame;
Serial.println("Send_CAN_Packet");
}
}
Beta Was this translation helpful? Give feedback.
All reactions