Softwire library blocks in case of hardware failure

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Softwire library blocks in case of hardware failure

Post by Phono »

Hi all,
i have interfaced a MPU6050 with an Olimexino STM32 board using the Softwire library. I was performing tests, and I tried to short SCL and SDA to produce an error and check whether it is correctly handled in my code. To my surprise, doing so blocks the execution somewhere in the library, so the called function does not return FALSE, and the error handling cannot take place.
Is anyone aware of this problem? I develop using the Arduino IDE, so no debug is possible.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Softwire library blocks in case of hardware failure

Post by fpiSTM »

There is no softWire library in the STM32 core. I guess you use Roger's core (leaflab)?
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Re: Softwire library blocks in case of hardware failure

Post by Phono »

Exactly. I found a place where a dead loop can occur. I added a simple timeout mechanism and it helped. The added lines are identified by the comment: JMD 30 March 2020

Code: Select all

void SoftWire::set_scl(bool state) {
	int Timeout = 10000 ;		// JMD 30 March 2020
	
    I2C_DELAY(this->i2c_delay);

	gpio_write_bit(sclDevice,sclBit, state);
//    digitalWrite(this->scl_pin,state);
    //Allow for clock stretching - dangerous currently
    if (state == HIGH) {
        while(digitalRead(this->scl_pin) == 0)		// JMD 30 March 2020
						if ( Timeout-- == 0 )		// JMD 30 March 2020
							return ;		// JMD 30 March 2020
    }
}
If there is a better way, I would appreciate.
Post Reply

Return to “General discussion”