1

we've had some troubles with TWI/I2C after waking up from sleep with the Atmel Xmega256A3. Instead of digging into the details of TWI/I2C we've decided to use the supplied twi_master_driver from Atmel attached to AVR1308 application note.

The problem is one or a few failed TWI transactions just after waking up from sleep. On the I2C-bus connected to the XMega we have a few potentiometers, a thermometer and an RTC. The XMega acts as the only master on the bus.

We use the sleep functions found in AVRLIBC:

{code for turning of VCC to all I2C connected devices}
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();
{code for turning on VCC to all I2C connected devices}

The XMega as woken from sleep by the RTC which sets a pin high. After the XMega is woken from sleep, we want to set a value on one of the potentiometers, but this fails. For some reason, the TWI-transaction result is TWIM_RESULT_NACK_RECEIVED instead of TWIM_RESULT_OK in the first transaction. After that everything seems to work again.

Have we missed anything here? Is there any known issues with the XMega, sleep and TWI? Do we need to reset the TWI of clear any flags after waking from sleep?

Best regards Fredrik

4

1 回答 1

2

I2C/TWI 上存在一个常见问题,即如果事务未完全完成,内部状态机会卡在中间状态。然后,在下一次事务处理时,从机不会正确响应。这通常发生在主机复位或在读取或写入过程中停止输出 SCK 信号时。一种解决方案是在开始任何数据事务之前手动切换 SCK 线 8 或 9 次,以便从设备中的内部状态机全部重置到传输点的开始,然后它们都在寻找它们的地址字节。

于 2011-04-01T12:32:11.237 回答