Is there a general I2C command to see if a device is still present on the bus after it is initialized once? For example an OLED display. The reason I ask this is to avoid the main program will freeze (when a device is disconnected) because of infinite loops present in the library code, in for example, the Wire library.
At startup of the MCU I want to check if a device is available or not and initialized when it is available. I do this with this function and works fine .....
bool MyClass::isPnpDeviceAvailable( uint8_t iAddress, bool bIsInitOnce = false )
{ // Try to start connection Wire.beginTransmission( iAddress ); // End connection without STOP command if already is initialized return ( Wire.endTransmission( !bIsInitOnce ) == 0x00 ); // No Error?, return true
}
.... however, when I want to check if a device is still there, before I perform an update, when I do this:
// 1.
if( isPnpDeviceAvailable( 0x3C, true )) { /* Cause program hang */ }
// 2.
if( isPnpDeviceAvailable( 0x3C )) { /* Cause display to turn off */ }
Is there a general command available, to say/send just a "Hello, are you there" and wait for a reply without sending START and STOP commands and without interrupting device/bus status?
Here is the proto-type device I made with attached (optional PNP I2C) display.
back soft...
ما را در سایت back soft دنبال می کنید
برچسب : نویسنده : استخدام کار backsoft بازدید : 314 تاريخ : دوشنبه 13 شهريور 1396 ساعت: 16:28