Skip to content

Where does the formula of BAUD comes from in SERCOM::initMasterWIRE( uint32_t baudrate ) #719

Open

Description

I've read in SAMD21 datasheet that the frequency generated for the I2C SCL line depends on the BAUD register.

Accoring to the documentation, this field should be generated using the following ecuations:

Bits 7:0 – BAUD[7:0] Master Baud Rate
This bit field is used to derive the SCL high time if BAUD.BAUDLOW is non-zero. If BAUD.BAUDLOW is zero, BAUD
will be used to generate both high and low periods of the SCL.
For more information on how to calculate the frequency, see SERCOM 25.6.2.3 Clock Generation – Baud-Rate
Generator.

I've seen in the code inside this method that clock frequency is generated using the following line:

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

I was willing to know where this ecuation comes from as in the documentation says that for Synchronous baudrate the following ecuation should be used:
image

From that point of view, should that line be something like this?:

// Synchronous arithmetic baudrate
  sercom->I2CM.BAUD.bit.BAUD = SystemCoreClock / ( 2 * baudrate) - 1;

The datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/SAM_D21_DA1_Family_DataSheet_DS40001882F.pdf, page 412-413

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions