Arduino Zero System Clock and I2C SCL frequency

I am trying to speed up the I2C SCL clock speed on my Arduino Zero which is communicating with an Analog Devices ADXL372 digital accelerometer. Using Wire.setClock, if I set my SCL to 100kHz I read a speed of 85kHz on my scope, and if I set my SCL to 400kHz, I read a speed of 315kHz. Digging deeper into the libraries I found that the I2C baud rate is defined as follows:

sercom->I2CM.BAUD.bit.BAUD = SystemCoreClock / ( 2 * baudrate) - 5 - (((SystemCoreClock / 1000000) * WIRE_RISE_TIME_NANOSECONDS) / (2 * 1000));

Now the Arduino Zero documentation says the CPU clock is 48MHz, but if you look in system_samd21.c, the macro __SYSTEM_CLOCK which is assigned to the variable SystemCoreClock is 1000000. Why is there this discrepancy?

If I plug in 1000000 to the calculation above I get negative numbers. What does this mean for the I2C SCL?

Furthermore, the datasheet for the SAMD21 says that it supports I2C speeds up to 3.4MHz.

Here's how I am setting up the I2C:

Wire.begin(i2c_addr);
Wire.setClock(400000);

Does anyone have any insight?

Edit: on further investigation, I find that SystemCoreClock is set equal to the macro VARIANT_MCK which is defined as 48000000ul in startup.c, but if I plug this value into the calculation above, for a 400kHz SCL I get the result 52. I have no idea what this means.

The description of the formula and how it's derived is described in section 28.6.2.4. of the datasheet (page 543).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.