AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
plexer
PostPosted: Apr 16, 2006 - 07:58 AM
Rookie


Joined: Aug 29, 2004
Posts: 26


I'm trying to get TWI working to communicate with a Real Time Clock, just for fun. Unfortunately I'm not having much luck. (Even using peter fleury's I2CMaster.h)

I'm pulling SCL and SDA high with 4.7k resistors.

I attatched an oscilloscope to SCL to see what was happening.. but nothing seems to be happening! Since it should be sending the start condition over and over again in a loop, I would have assumed there would be some activity.

[edit] As far as I can tell the AVR (mega16L) never gets past this while loop:

Code:
   
// send START condition
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);

// wait until transmission completed
while(!(TWCR & (1<<TWINT)));


Shouldn't the AVR be able to send the start condition even if there was a dead / no chip at all connected to the SCL and SDA pins? What would stop it sending the condition / realising its sent it?

Thankyou for any help in advance,
Plex
 
 View user's profile Send private message  
Reply with quote Back to top
peret
PostPosted: Apr 18, 2006 - 12:13 AM
Raving lunatic


Joined: May 26, 2004
Posts: 2024
Location: Las Vegas, Nevada

It should be able to send the start condition even with nothing connected, because until it completes a transfer it can't know if there's a device connected. I'm not sure, though, whether it can send one start condition after another without a data byte in between. I've made it lock up by sending two stop conditions one after another. Run a proper start/address cycle and see if that makes any difference. You probably should check the TWWC bit in TWCR, and look at the status register, for further clues.
 
 View user's profile Send private message  
Reply with quote Back to top
Spamiam
PostPosted: Apr 18, 2006 - 01:32 AM
Resident


Joined: Apr 12, 2005
Posts: 954


Hmmm, I used Fleury's I2C stuff without ANY problems at all. So, since you have an o-scope, why don't you try simple toggling the TWI pins in software, just high-low-high.... to see that the pins are working and the scope is showing you what you expect to see.

Then use the non-interrupt driven functions to see how the I2C pins are working, then use the interrupt driven functions. For me, they all work fine.

-Tony
 
 View user's profile Send private message  
Reply with quote Back to top
sravanmx
PostPosted: Apr 18, 2006 - 03:07 AM
Newbie


Joined: May 11, 2005
Posts: 4


I am getting this exact same problem as well
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits