adjust can to hopefull work better

This commit is contained in:
2026-04-01 21:43:16 +02:00
parent eaa65637f1
commit 1fa765a5d8
2 changed files with 15 additions and 11 deletions

View File

@@ -251,12 +251,12 @@ async fn main(spawner: Spawner) {
// Improve CAN robustness for longer cables:
// 1. Enable Automatic Bus-Off Management (ABOM)
// 2. Ensure No Automatic Retransmission (NART) is DISABLED (i.e. we WANT retransmission)
// 2. Disable Automatic Retransmission (NART) as we send regular measurements anyway
// 3. Enable Receive FIFO Overwrite Mode (RFLM = 0, default)
// 4. Increase Resync Jump Width (SJW) if possible by patching BTIMR
hal::pac::CAN1.ctlr().modify(|w| {
w.set_abom(true);
w.set_nart(false); // HAL default is usually false, but let's be explicit
w.set_abom(false);
w.set_nart(true);
});
// SJW is bits 24-25 of BTIMR. HAL sets it to 0 (SJW=1).

View File

@@ -367,11 +367,13 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
let config = self.twai_config.take().expect("twai config not set");
let mut twai = config.into_async().start();
let res = (async {
if twai.is_bus_off() {
bail!("Bus offline after start");
info!("Bus offline after start, attempting recovery");
// Re-start to initiate recovery
twai = twai.stop().start();
}
let res = (async {
Timer::after_millis(10).await;
let mut moistures = Moistures::default();
@@ -395,11 +397,13 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
let config = self.twai_config.take().expect("twai config not set");
let mut twai = config.into_async().start();
let res = (async {
if twai.is_bus_off() {
bail!("Bus offline after start");
info!("Bus offline after start, attempting recovery");
// Re-start to initiate recovery
twai = twai.stop().start();
}
let res = (async {
Timer::after_millis(1000).await;
info!("Sending info messages now");
// Send a few test messages per potential sensor node