Forum Menu




 


Log in Problems?
New User? Sign Up!
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
Spamiam
PostPosted: Jun 16, 2010 - 02:22 PM
Posting Freak


Joined: Apr 12, 2005
Posts: 1053


I am trying to calculate the SCL clock rate given the prescaler and TWBR

The datasheet says SCL = F_CPU/(16 + 2*TWBR*Prescaler)

I am looking for 400KHz clock rate on an M644PA running at 18.432MHz. It seems as if I have to use rather low values of TWBR even at a prescaler of 1.

For a prescaler of 1, I calculate a TWBR of 15 to give a clock rate of 400,696Hz. Is this correct?

I guess I expected a larger value for TWBR and/or a larger prescaler on a CPU running this fast. It appears that there is a lot of room to slow down the TWI clock, but not much room to increase the clock especially on slower CPUs!

-Tony
 
 View user's profile Send private message  
Reply with quote Back to top
John_A_Brown
PostPosted: Jun 16, 2010 - 04:02 PM
Raving lunatic


Joined: Sep 20, 2003
Posts: 4852
Location: Surrey, England

Isn't 400kHz the maximum speed for vanilla I2C?
 
 View user's profile Send private message  
Reply with quote Back to top
Spamiam
PostPosted: Jun 16, 2010 - 04:21 PM
Posting Freak


Joined: Apr 12, 2005
Posts: 1053


John_A_Brown wrote:
Isn't 400kHz the maximum speed for vanilla I2C?


It is, but my gut feeling was telling me that if a 1 or 2 MHz device is going to get to 400KHz, then I would be using a larger prescaler or a TWBR greater than just 15 or 16 on a 18.432MHz device.

Is my TWBR calculation correct?

-Tony
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Jun 16, 2010 - 04:32 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 19464
Location: Wormshill, England

Code:

SCL = F_CPU/(16 + 2*TWBR*Prescaler)
SCL = 18432000/(16 + 2*15*1) = 400696 Hz
16 + 2*TWBR = F_CPU/SCL
TWBR = 0.5((F_CPU/SCL) - 16)
TWBR = 0.5((1843200/400000) - 16) = 15.04


I can never understand what the prescaler bits are for. You effectively end up with very slow bus for any values of the prescaler.

Just out of interest, measure your clock speed with a scope or logic analyser. You will get a surprise!

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
stu_san
PostPosted: Jun 16, 2010 - 04:36 PM
Raving lunatic


Joined: Dec 30, 2005
Posts: 2327
Location: Fort Collins, CO USA

Another off-the-side comment: Just because your TWI devices say they can do 400K does not mean that they actually can.

One of our designs uses the Philips PCA9555 I/O Expander. It's rated at 400 KHz, right there in the datasheet. In actual use we found the thing never works reliably over 100 KHz.

Caveat Emptor! (or, "Them's that don't look sometimes get took.")

Stu

_________________
Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!
 
 View user's profile Send private message  
Reply with quote Back to top
John_A_Brown
PostPosted: Jun 17, 2010 - 09:09 AM
Raving lunatic


Joined: Sep 20, 2003
Posts: 4852
Location: Surrey, England

John_A_Brown wrote:
Isn't 400kHz the maximum speed for vanilla I2C?

Seems I was wrong. ATW the standard speed is 100kHz.
 
 View user's profile Send private message  
Reply with quote Back to top
Spamiam
PostPosted: Jun 22, 2010 - 03:07 AM
Posting Freak


Joined: Apr 12, 2005
Posts: 1053


The specific device I am going to work with is the MCP4725. It is rated for 100KHz and 400KHZ, and with a special command it will do 3.4MHz. I can't get the TWI up to 3.4 MHz, but as long as the AVR's clock exceeds 6.4MHz, I can get 400MHZ on the TWI bus.

I will soon find out if the ratings are real or hype. I will not have particularly long leads to the DAC chip, less than 25mm.

-Tony
 
 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