I2C communication flow protection (timeout)

6 posts / 0 new
Last post
Vadym
Offline
Last seen:1 year 2 months ago
Joined:2015-08-13 08:28
I2C communication flow protection (timeout)

Hi.

I connect DA14580 to RTC device PCF85263A via I2C communication, DA14580 in master role, SDK 5.0.3.
I used the Dialog official I2C driver for eeprom from "DA14580_peripheral example code" and it works when the external device (RTC) connected to the BUS.
When RTC device disconnected and not responding (there isn't ACK) the SW goes into infinite loop in function "i2c_wait_until_eeprom_ready".

Do you have some example or HW solution in I2C module for this problem like timeout or module restart?

我认为问题是same tohttp://support.dialog-semiconductor.com/i2c-communication-eeprom-24lc08b

Thanks,
Vadym.

Device:
MT_dialog
Offline
Last seen:2 months 5 days ago
Staff
Joined:2015-06-08 11:34
Hi Vadym,

Hi Vadym,

Please check the post below,

http://support.dialog-semiconductor.com/i2c-read-hangs-waitforreceivedbyte

Thanks MT_dialog

Vadym
Offline
Last seen:1 year 2 months ago
Joined:2015-08-13 08:28
Hi.

Hi.

I consider a option to implement a timeout handling with the hardware timer TMR0 for timeout reading.
In function "read_data_single" there is part, when all interrupt are disabled. And when there is no answer from I2C slave, the program wait exactly in the part, when interrupt are disabled.
If I understand right, I will not receive the timer interrupt callback and I need to test TMR by polling?
How can I get indication of TMR0 was overlap or any another flag from TMR0?

Where can I find API or detail description of I2C and TMR0 modules?

Thanks,
Vadym.

MT_dialog
Offline
Last seen:2 months 5 days ago
Staff
Joined:2015-06-08 11:34
Hi Vadym,

Hi Vadym,

Yes, if the interrupts are disabled you wont get an interrupt from the timer, so you can try to poll the timer by reading the values from the timer registers TIMER0_ON_REG or you can poll the pending interrupts with the NVIC_GetPendingIRQ(IRQn_Type IRQn) in order to check if the SWTIM_IRQn has occured, and clear the interrupt after in order to wait for another timer interrupt. I think the later is better.

Thanks MT_dialog

Vadym
Offline
Last seen:1 year 2 months ago
Joined:2015-08-13 08:28
Hi.

Hi.

I try to use TIMER0 for the timeout purpose.
The timer initialized and started in next way:
void timeoutTimer0_init(void)
{
timer0_stop();
timer0_register_callback(timer0_general_user_callback_function);
set_tmr_enable(CLK_PER_REG_TMR_ENABLED);
set_tmr_div(CLK_PER_REG_TMR_DIV_8);
timer0_set_pwm_high_counter(NO_PWM);
timer0_set_pwm_low_counter(NO_PWM);
timer0_init(TIM0_CLK_FAST, PWM_MODE_ONE, TIM0_CLK_DIV_BY_10);
}
void timeoutTimer0_start_10ms(void)
{
timer0_disable_irq();
timer0_set_pwm_on_counter(RELOAD_10MS); //2000
timer0_start();
timer0_enable_irq();
}

I receive first interrupt in the very small time (I was unsuccessful to measure it). And after i get interrupt in expected time (10mSec).
Does the Timer value (TIMER0_ON_REG) loaded from some "reload value" only when the timer "overrun" happens with interrupt generation?
Or is my sequence of timer setup is wrong?

Thanks!

MT_dialog
Offline
Last seen:2 months 5 days ago
Staff
Joined:2015-06-08 11:34
Hi Vadym,

Hi Vadym,

The value that you place in the TIMER_ON_REG is the value that reloads every time the timer counts down to zero, I dont see anything wrong with how you set your timer although you can have a look how to timer is used in the SDK at the following directory \peripheral_examples\timer0\timer0_general\. About the interrupt you get almost immidiatelly after you start the timer is part of the timer functionallity, you can't avoid it, just ignore it.

Thanks MT_dialog