Page 1 of 1

TD1208 I2C issue after power cycle

Posted: Wed Aug 17, 2016 2:15 pm
by Siemen
Hello,

I have an issue using the TD1208 when I am reading sensor values via I2C.
Everything works perfect when I flash the firmware (which includes a reset via the reset pin).

However, when I power cycle the device (disconnect wires for power and reconnect), the program does not run properly.
On the scope, the SCL and SDA lines both suddenly return from low (pulled down) to high (released).
Depending on slight changes in the code, this moment occurs in the somewhere during the sending of the device I2C bus address.
In my last test, this was during the 6th clock cycle.

Does anyone have a similar issue like this (different I2C behaviour for power cycle vs reset pin toggle)?

Re: TD1208 I2C issue after power cycle

Posted: Wed Aug 24, 2016 9:18 am
by mstempin
No, but I had issues in the past with I2C because of an undocumented trick within EnergyMicro's I2C implemetnation of the I2C in "lib/emlib/em_i2c.c": the "I2C_TypeDef *" passed to the "I2C_Transfer()" function must be static, within the caller's code, as it contains the Finite State Automaton current state.

If the I2C_TypeDef structure is allocated in the caller's stack as a dynamic structure, you get what is left in memory between stack calls, i.e. garbage. This mays explain why it is working when you Flash for the first time and when you reboot the device.