You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing an application for the ESP32 using the CAN protocol. I have used the esp_hal::Twai crate for this implementation. However, I am facing an issue with CAN message transmission. The byte array data for the CAN message has been encoded into different bits, and I have set the CAN Frame ID as zero according to the provided example. However, it is being encoded into another Frame ID, specifically 0x3B9.
Below is the code I used along with the CAN dump output.
Code:
#![no_std]#![no_main]constIS_FIRST_SENDER:bool = true;use esp_backtrace as _;use embedded_can::nb::Can;use esp_hal::{
clock::ClockControl,
gpio::Io,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
twai::{self, filter::SingleStandardFilter,EspTwaiFrame,StandardId},};use esp_println::println;use nb::block;#[entry]fnmain() -> ! {let peripherals = Peripherals::take();let system = SystemControl::new(peripherals.SYSTEM);let clocks = ClockControl::boot_defaults(system.clock_control).freeze();let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);let can_tx_pin = io.pins.gpio5;let can_rx_pin = io.pins.gpio4;// The speed of the CAN bus.constCAN_BAUDRATE: twai::BaudRate = twai::BaudRate::B500K;println!("baud: {}", matchCAN_BAUDRATE{
twai::BaudRate::B500K => "500K",
twai::BaudRate::B125K => "125K",
twai::BaudRate::B250K => "250K",
twai::BaudRate::B1000K => "1000K",
twai::BaudRate::Custom(_) => todo!(),
});letmut can_config = twai::TwaiConfiguration::new(
peripherals.TWAI0,
can_tx_pin,
can_rx_pin,&clocks,CAN_BAUDRATE,None,);// Define the CAN filter// let filter = SingleStandardFilter::new(StandardId::new(0x000).unwrap(), 0x000);// can_config.set_filter(filter);letmut can = can_config.start();loop{// Send the CAN messagelet frame = EspTwaiFrame::new(StandardId::new(0x010).unwrap().into(),&[14,20,3]).unwrap();println!("Frame data: {:?}", frame);matchblock!(can.transmit(&frame)){Ok(_) => println!("Frame transmitted"),Err(e) => println!("Failed to transmit frame: {:?}", e),}}}
CAN Dump Output:
Problem:
The CAN Frame ID is set to 0x010 in the code, but the actual transmission is showing a different Frame ID (0x3B9).
I would like to understand how to correctly transmit the actual CAN message without modifying the Frame ID.
Any help or clarification on how to resolve this issue would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
vibhanshuverma02
changed the title
ncorrect CAN Frame ID during Message Transmission
Incorrect CAN Frame ID during Message Transmission
Sep 5, 2024
I am writing an application for the ESP32 using the CAN protocol. I have used the esp_hal::Twai crate for this implementation. However, I am facing an issue with CAN message transmission. The byte array data for the CAN message has been encoded into different bits, and I have set the CAN Frame ID as zero according to the provided example. However, it is being encoded into another Frame ID, specifically 0x3B9.
Below is the code I used along with the CAN dump output.
Code:
CAN Dump Output:
Problem:
Any help or clarification on how to resolve this issue would be greatly appreciated.
The text was updated successfully, but these errors were encountered: