cancel
Showing results for 
Search instead for 
Did you mean: 

How can I detect if there is CAN-bus activity going on, when the packets aren't for me (they're filtered away)?

arnold_w
Senior

I am working with the STM32F446-microcontrollers and I have several of them connected together through a common CAN-bus. I am using packet filtering in a standard way to ensure that only the intended microcontroller acts upon a specific packet. However, I am using Stop Mode to save power and this means I need to send a wake up packet and all microcontrollers will wake up when such a packet appears. Before the microcontrollers enters Stop Mode I enable external interrupts on the CAN Rx pin and when an external interrupt happens (= we receive a CAN-bus packet) I immediately turn off external interrupts to avoid getting half a million (or so) interrupts per second (I clock the CAN-bus at 500 kHz). I need to make sure that ALL CAN-bus devices stay awake for entire duration (sometimes I send bursts of hundred of packets tightly after each other) of the transactions because otherwise I get a raise condition (I enable the external interrupt and then immediately get an external interrupt, which will disable external interrupts, and then I enter Stop Mode and never, ever wake up again because external interrupts are turned off). Does anybody have a suggestion how the inactive microcontrollers (those that filter away the currently transmitting packets) can detect if there is CAN-bus activity going on (and thus, aren't allowed to go to Stop Mode)? I understand that it's not possible to read the CAN Rx-pin using GPIOx->ODR or GPIOx->IDR since the pin is configured as Alternate.

1 REPLY 1
arnold_w
Senior

I think I found out a way to accomplish this. On pins GPIO_PIN_0, GPIO_PIN_1, ..., GPIO_PIN_4 (the higher pins have shared interrupts in NVIC so they could potentially conflict with external interrupts that we actually need when not in Stop Mode) I can disable interrupts, upon wakeup from Stop Mode, using NVIC_DisableIRQ instead of clearing the corresponding bit in EXTI->IMR. Then the corresponding EXPI->PR bit will be set, but I won't get any interrupts, as long as there is CAN-bus activity on the pin. So, I can poll the corresponding EXTI->PR bit to see whether it's ok to enter Stop Mode or not.