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.
Sleep mode and Wake up when CAN is active
Re: Sleep mode and Wake up when CAN is active
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.
Re: Sleep mode and Wake up when CAN is active
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.
Re: Sleep mode and Wake up when CAN is active
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.
Re: Sleep mode and Wake up when CAN is active
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?
Re: Sleep mode and Wake up when CAN is active
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:esp_restart() does a full reset of all peripherals
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.brp80000 wrote:How can I do a full restart like with a hard reset?
Re: Sleep mode and Wake up when CAN is active
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: Google [Bot] and 137 guests