Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

I2C supported clock speeds
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

I2C supported clock speeds

by SkyRyder on Wed Oct 27, 2021 8:07 pm

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!

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

Re: I2C supported clock speeds

by User_UMjT7KxnxP8YN8 on Thu Oct 28, 2021 6:54 pm

From wire.h:

Code: Select all | TOGGLE FULL SIZE
    // TWI clock frequency
    static const uint32_t TWI_CLOCK = 100000;


From wire.cpp:

Code: Select all | TOGGLE FULL SIZE
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_UMjT7KxnxP8YN8
 
Posts: 272
Joined: Tue Jul 17, 2018 1:28 pm

Re: I2C supported clock speeds

by SkyRyder on Fri Oct 29, 2021 2:31 am

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.

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

Re: I2C supported clock speeds

by User_UMjT7KxnxP8YN8 on Fri Oct 29, 2021 1:17 pm

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 | TOGGLE FULL SIZE
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/mchp/documents/MCU32/ProductDocuments/DataSheets/SAM_D5x_E5x_Family_Data_Sheet_DS60001507G.pdf

User_UMjT7KxnxP8YN8
 
Posts: 272
Joined: Tue Jul 17, 2018 1:28 pm

Please be positive and constructive with your questions and comments.