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

von Achim Meyer (Guest)

Rate this post
0 useful
not useful

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 

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?


von Achim Meyer (Guest)

Rate this post
0 useful
not useful
Sorry, i accidentally wrote

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

but of course i'm using master-mode!


von Achim Meyer (Guest)

Rate this post
0 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 

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




Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.