EmbDev.net

Forum: µC & Digital Electronics TWI (i2c) on Atmel atiny204/404/804


von Achim Meyer (Guest)


Rate this post
useful
not useful
Hello,

has somebody successfully used the twi (hardware) on one of the 
(relatively new) tiny-x04 chips?

I'm stuck already while trying to issue a start-condition/transmit slave 
address:

After the suggested initialisation (datasheet) i'm writing TWI0.MADDR 
(slave-mode) and then waiting for the WIF flag in TWI0.MSTATUS to get 
set, but it never gets set. I didn't hook it up to an oszi to check 
wether it starts to write the address anyways, but i suspect it doesn't.

I also took a look into the datasheets of related Devices (414, 817...) 
and went through an (quite overengineered) example on start.atmel.com - 
but didn't find any obvious difference in the end.

So maybe i'll revert to bit-banging but i'm just curious: Did someone 
succeed with the hardware-twi on one of those chips?

Cheers,
Achim

von Achim Meyer (Guest)


Rate this post
useful
not useful
Sorry, i accidentally wrote

>> i'm writing TWI0.MADDR (slave-mode)

but of course i'm using master-mode!

Achim

von Achim Meyer (Guest)


Rate this post
useful
not useful
Solved it!

My misconception was that the WIF-flag in TWI0.MSTATUS would get always 
set after a write to TWI0.MADDR to indicate that the transmission of the 
address was finished (the datasheet is a bit fuzzy about that)

Instead it depends on wether you do a write or a read access (bit 0 of 
address either 1 or 0). If you do a read access the WIF-flag will not 
get set after transmitting the address, the master just proceeds with 
reading one byte from the slave an then sets the RIF-flag. So you have 
to check that flag (instead of WIF) when doing a read-access (of course 
the same applies when you're using irq's instead of simply polling the 
flags)

Here's the link that helped me to get on track:

https://www.avrfreaks.net/comment/2568566#comment-2568566

Achim

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.