TWI (i2c) on Atmel atiny204/404/804

Guest #6173798
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
Guest #6174414
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

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.