some cleaning
This commit is contained in:
parent
172e319720
commit
37ec9114b3
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.7"
|
||||
cortex-m-rt = "0.7"
|
||||
cfg-if = "1"
|
||||
embedded-io = "0.6"
|
||||
|
@ -58,29 +58,31 @@ async fn main(_spawner: Spawner) {
|
||||
// Base channel which has dedicated mask.
|
||||
let mut rx_base = CanRx::new(channels.take(14).unwrap());
|
||||
let standard_id = can::StandardId::new(0x42).unwrap();
|
||||
let send_frame = CanFrame::Normal(
|
||||
CanFrameNormal::new(can::Id::Standard(standard_id), &[1, 2, 3, 4]).unwrap(),
|
||||
);
|
||||
let send_data = &[1, 2, 3, 4];
|
||||
let send_frame =
|
||||
CanFrame::Normal(CanFrameNormal::new(can::Id::Standard(standard_id), send_data).unwrap());
|
||||
rx_dedicated
|
||||
.configure_for_reception_with_standard_id(standard_id, false)
|
||||
.unwrap();
|
||||
rx_base.configure_for_reception();
|
||||
defmt::info!("sending CAN frame");
|
||||
defmt::info!("sending CAN frame with ID 0x42 and data {}", send_data);
|
||||
tx.transmit_frame(send_frame).unwrap();
|
||||
let frame = nb::block!(rx_dedicated.receive(true)).expect("invalid CAN rx state");
|
||||
let err_counter = can.read_error_counters();
|
||||
defmt::info!(
|
||||
"error count tx {}, error count rx {}",
|
||||
err_counter.transmit(),
|
||||
err_counter.receive()
|
||||
);
|
||||
let diag = can.read_error_diagnostics();
|
||||
defmt::info!("EFID: {}, EBID: {}", diag.efid(), diag.ebid());
|
||||
if err_counter.transmit() > 0 || err_counter.receive() > 0 {
|
||||
defmt::warn!(
|
||||
"error count tx {}, error count rx {}",
|
||||
err_counter.transmit(),
|
||||
err_counter.receive()
|
||||
);
|
||||
let diag = can.read_error_diagnostics();
|
||||
defmt::warn!("EFID: {}, EBID: {}", diag.efid(), diag.ebid());
|
||||
}
|
||||
match frame {
|
||||
CanFrame::Normal(can_frame_normal) => match can_frame_normal.id() {
|
||||
can::Id::Standard(standard_id) => {
|
||||
defmt::info!(
|
||||
"received CAN frame with ID {} and data {}",
|
||||
"received CAN frame with ID {:#X} and data {}",
|
||||
standard_id.as_raw(),
|
||||
can_frame_normal.data()
|
||||
);
|
||||
@ -91,7 +93,9 @@ async fn main(_spawner: Spawner) {
|
||||
defmt::error!("received unexpected CAN remote frame");
|
||||
}
|
||||
}
|
||||
loop {}
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
#[interrupt]
|
||||
|
Loading…
x
Reference in New Issue
Block a user