Currently I'm developing an application that uses hot-pluggable I2C nodes. To determine if a node is connected, I use a loop to poll all the addresses where nodes could possible live.
When read-through-write to a address that's not available my application breaks and waits forever in the _unhandled_exception(). When I logic analyse the data, it looks like this:
(click for large)
I'm trying to make the i2c calls as synchronous as possible. Therefore my mcuconf.h looks like this:
Code: Select all
/*
* I2C driver system settings.
*/
#define STM32_I2C_USE_I2C1 TRUE
#define STM32_I2C_USE_I2C2 TRUE
#define I2C_SUPPORTS_CALLBACKS FALSE
#define STM32_I2C_I2C1_IRQ_PRIORITY 10
#define STM32_I2C_I2C2_IRQ_PRIORITY 10
#define STM32_I2C_I2C1_DMA_PRIORITY 4
#define STM32_I2C_I2C2_DMA_PRIORITY 4
#define STM32_I2C_I2C1_DMA_ERROR_HOOK() chSysHalt()
#define STM32_I2C_I2C2_DMA_ERROR_HOOK() chSysHalt()
/* I2C1 */
//#define STM32_I2C_I2C1_USE_GPT_TIM GPTD1
#define STM32_I2C_I2C1_USE_POLLING_WAIT TRUE
/* I2C2 */
//#define STM32_I2C_I2C2_USE_GPT_TIM GPTD2
#define STM32_I2C_I2C2_USE_POLLING_WAIT TRUEHence the commented out GPT!
The error reproduces on I2C1 as well I2C2.
To fix this problem, I disabled the I2C_CR2_ITERREN for both the I2C busses
Code: Select all
#define I2C_CR2_ITERREN ((uint16_t)0x0000) /*!< Error Interrupt Enable */
But when I run the application and try to read from a nonexisting address, it keeps looping in the
Code: Select all
void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr,
uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes) {
...
while (!(i2cp->id_i2c->SR1 & I2C_SR1_ADDR))
;
...
On the logic analyser, it looks like this
Is there a way to let the application time out after a number of milliseconds?
I also found the I2C_POLLING_TIMEOUT (0xFFFF default) lowered it to 0x00FF, but that doesn't seem to affect the hung.
Can anybody help me out on this one?
I'm currently at 2.3.4 rev 3451. Is it worth updating?
Thanks in advance!
matis