Author Message
 Spamiam
 Posted: Jun 16, 2010 - 02:22 PM
 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

 John_A_Brown
 Posted: Jun 16, 2010 - 04:02 PM
 Joined: Sep 20, 2003 Posts: 5018 Location: Surrey, England
 Isn't 400kHz the maximum speed for vanilla I2C?

 Spamiam
 Posted: Jun 16, 2010 - 04:21 PM
 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

 david.prentice
 Posted: Jun 16, 2010 - 04:32 PM
 Joined: Feb 12, 2005 Posts: 20668 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.

 stu_san
 Posted: Jun 16, 2010 - 04:36 PM
 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!

 John_A_Brown
 Posted: Jun 17, 2010 - 09:09 AM
 Joined: Sep 20, 2003 Posts: 5018 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.

 Spamiam
 Posted: Jun 22, 2010 - 03:07 AM
 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

 Display posts from previous:  All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 Jump to: Select a forum Forum index|--[AVR (8-bit) Technical Forums]|   |-- AVR forum|   |-- XMEGA forum|   |-- AVR Wireless forum|   |-- AVR GCC forum|   |-- AVR Studio 5 and Atmel Studio 6 forum|   |-- AVR studio 4 forum|   |-- AVRfreaks Academy forum|   |-- AVR Tutorials|--[AVR Software Framework]|   |-- AVR Software Framework|--[AVR32 (32-bit) Technical Forums]|   |-- AVR32 Linux Forum|   |-- AVR32 General (standalone)|   |-- AVR32 Software Tools|   |-- AVR32 Hardware|--[General Electronics Technical Forums]|   |-- General Electronics|   |-- Atmel Security Products|--[Non-technical forums]|   |-- AVRfreaks.net Housekeeping|--[Non-topical forums]|   |-- Off-topic forum|   |-- AVRfreaks Trading Post
All times are GMT + 1 Hour