Sleep mode and Wake up when CAN is active

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Sleep mode and Wake up when CAN is active

Postby brp80000 » Fri Feb 15, 2019 10:17 pm

I want the device to go to sleep when there is no activity on the CAN bus (no transmission of any packets). And woke up back, at the beginning of transmission of any packets on CAN. Can this mode be implemented programmatically, because the built-in can controller SJ1000 must be able to do it.
In General, I need to turn off everything that is possible and wait for the appearance of any packages in CAN. I can't find any description or examples of this.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Sleep mode and Wake up when CAN is active

Postby ESP_igrr » Sat Feb 16, 2019 3:54 am

There is no direct way of doing this as CAN controller runs from the APB clock, and doesn't have the low-power wake up feature which UART has, for example. You could probably get something close to your requirement if you place the device into light sleep mode, and set up wake up on GPIO (EXT0 or EXT1). This GPIO can then be connected to the output of CAN transceiver. Net result will be that when CAN message is sent, ESP32 will wake up from light sleep. Note however that the CAN packet which will be triggering the wake up will not be captured by the CAN controller correctly, as it takes approximately 30 microseconds to exit light sleep and re-enable the APB clock from PLL. Depending on the use case this may or may not be an issue though, as the sender of the packet may retransmit it seeing the lack of response. This is probably not exactly what you are looking for, but may still be worth trying.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Sleep mode and Wake up when CAN is active

Postby brp80000 » Sat Feb 16, 2019 8:06 am

Losing the can packet on Wake up is completely irrelevant to me. I use as IO17 IO16 as CAN_TX and CAN_RX. Can I use the activity control of the same GPIOs in sleep mode, and after waking up use these GPIOs as TX and RX for CAN.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Sleep mode and Wake up when CAN is active

Postby ESP_igrr » Sat Feb 16, 2019 8:30 am

No, RTC wakeup sources (EXT0/EXT1) can use the pins in RTC power domain. GPIO16/17 are in VDDSDIO power domain. You can check the pin list in the end of the data sheet, or check the GPIO section of the TRM for the list of RTC capable pins. If you pick an RTC capable pin for RX, then what you describe should be possible.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Sleep mode and Wake up when CAN is active

Postby brp80000 » Sat Feb 16, 2019 11:04 pm

I used a TX CAN and gpio 4 connection and it works. I made that my code in the absence of packages in CAN within 10 seconds did restart ESP and at the beginning of a code passed from a light sleep and waited for awakening on GPIO 4. It works, but esp_restart() does a full reset of all peripherals. How can I do a full restart like with a hard reset?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Sleep mode and Wake up when CAN is active

Postby ESP_igrr » Sun Feb 17, 2019 8:08 am

brp80000 wrote:esp_restart() does a full reset of all peripherals
It only resets some of the peripherals: UART, SPI, SDIO... CAN is not reset, I think. However if you want to reset the CAN you can call periph_module_reset function.
brp80000 wrote:How can I do a full restart like with a hard reset?
The closest you can get is an RTC Watchdog reset, which will reset the entire chip. There are some functions in soc/rtc.h to control this WDT. Be warned though — the chip will capture values of strapping pins on such a reset. If GPIO0 happens to be low, for example, the chip will end up in bootloader mode as a result.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Sleep mode and Wake up when CAN is active

Postby brp80000 » Sun Feb 17, 2019 8:37 am

tell me the name of the function to activate the restart by WDT soc/rtc.h I did not find anything similar

Who is online

Users browsing this forum: No registered users and 120 guests