How to gracefully handle failed i2c connection

flimsy
Posts: 6
Joined: Mon Nov 06, 2023 3:41 am

How to gracefully handle failed i2c connection

Postby flimsy » Wed Jan 17, 2024 5:23 am

I've implemented an OLED display over i2c, and I'm trying to figure out whether there is a graceful way to fail to initialize the display gracefully and continue executing the rest of the behavior without the display. Currently when the display is not connected, the ESP boot loops with an error when `i2c_master_cmd_begin` executes. Is there a way to simply handle this failure and move on?

ESP_Sprite
Posts: 9052
Joined: Thu Nov 26, 2015 4:08 am

Re: How to gracefully handle failed i2c connection

Postby ESP_Sprite » Wed Jan 17, 2024 5:59 am

You'd catch that error manually (I imagine at the moment it's caught by an ESP_ERROR_CHECK macro or something that causes the panic and reboot) and then set a flag so the rest of the program won't try to write to the non-existent display anymore.

flimsy
Posts: 6
Joined: Mon Nov 06, 2023 3:41 am

Re: How to gracefully handle failed i2c connection

Postby flimsy » Wed Jan 17, 2024 6:24 pm

Ah OK, I think I understand what's going on. Thank you!

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 206 guests