I2C supported clock speeds

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
SkyRyder
 
Posts: 45
Joined: Fri Mar 06, 2020 6:05 pm

I2C supported clock speeds

Post by SkyRyder »

Hi all,

I could not find what clock speeds metro express airlift supports for I2c (via the Wire.setClock() function).

Also, what is the default speed? (usually 100kHz, right?)

Anyone know?

Thank you!

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: I2C supported clock speeds

Post by User_UMjT7KxnxP8YN8 »

From wire.h:

Code: Select all

    // TWI clock frequency
    static const uint32_t TWI_CLOCK = 100000;
From wire.cpp:

Code: Select all

void TwoWire::begin(void) {
  //Master Mode
  sercom->initMasterWIRE(TWI_CLOCK);
  sercom->enableWIRE();

  pinPeripheral(_uc_pinSDA, g_APinDescription[_uc_pinSDA].ulPinType);
  pinPeripheral(_uc_pinSCL, g_APinDescription[_uc_pinSCL].ulPinType);
}

User avatar
SkyRyder
 
Posts: 45
Joined: Fri Mar 06, 2020 6:05 pm

Re: I2C supported clock speeds

Post by SkyRyder »

If I understand this correctly, the default speed is 100000kHz?

what speeds are "legal" to use that are significantly slower? Is there a document on this that a newbie can understand?

I believe the command Wire.setClock() is how it is set, correct? should it be called before or after Wire.begin?

Thank you.

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: I2C supported clock speeds

Post by User_UMjT7KxnxP8YN8 »

It's 100 KHz. I'm just looking at the code, which you can do too. On a Windows PC, it's located at
C:\Users\[YOUR_USERNAME_HERE]\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.11\libraries\Wire

From wire.cpp:

Code: Select all

void TwoWire::setClock(uint32_t baudrate) {
  sercom->disableWIRE();
  sercom->initMasterWIRE(baudrate);
  sercom->enableWIRE();
}
Other useful resources include the official Arduino refence page for Wire at https://www.arduino.cc/en/Reference/WireSetClock which says:
Wire.setClock()
Description
This function modifies the clock frequency for I2C communication. I2C slave devices have no minimum working clock frequency, however 100KHz is usually the baseline.

Syntax
Wire.setClock(clockFrequency)

Parameters
clockFrequency: the value (in Hertz) of desired communication clock. Accepted values are 100000 (standard mode) and 400000 (fast mode). Some processors also support 10000 (low speed mode), 1000000 (fast mode plus) and 3400000 (high speed mode). Please refer to the specific processor documentation to make sure the desired mode is supported.
You can find the ATSAMD51 processor family datasheet at https://www.microchip.com/content/dam/m ... 01507G.pdf

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”