This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI Master : SCL frequency > 400kHz

I'm successfully using nRF52832 on custom designed PCBs.  I've been trying I2C communication (nRF is the Master) using the TWIM driver.  This has worked successfully at 100kHz, 250kHz and 400kHz.

I wish to increase the communications speed as much as possible (the slave device is capable of 1000kHz clock speed).  I've experimented with changing the FREQUENCY register: 

https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Ftwi.html&cp=3_1_0_48_7_9&anchor=register.FREQUENCY

There doesn't seem to be an exact mapping between the register value and the achieved SCL frequency, but I was able to get SCL @ ~800kHz by programming the above register to 0x0C380D40 = 205000000 (decimal).

To get this high speed I also had to set the GPIO configuration to "high drive strength" for both "0" and "1" signals.  

I'd like to know if anyone else has experimented with this, and any problems they encountered.  Am I likely to encounter problems with Nordic SDK drivers because of running at "out of spec" SCL frequency?  Is this going to have huge impact on power requirements?

Thanks for any information!

  • The answer to all your questions is: we don't know, it's not been tested.

    The FREQUENCY register is shared between TWI/TWIM/SPI/SPIM and the register value is only valid in a peripheral's own context, ie, 0x0C380D40 has a different result when used by the other serial peripherals, ie magnitude is not linear with frequency.


  • Bumping this thread again, I too am curious at getting close to 1MHz I2C speeds. I tried the solution, setting FREQUENCY register to 0x0C380D40 (I didn't set drive strength but does this matter?) but the SCL line still clocks at exactly 400kHz.

     EDIT:

    Never-mind. You actually do have to set high drive strength, or it just doesn't clock at that rate.

    The enum NRF_TWIM_FREQ_800K is = 209715200

    nrfx_twim_config_t config =
    {
    .frequency = NRF_TWIM_FREQ_800K,
    .scl = I2C_SCL_PIN,
    .sda = I2C_SDA_PIN,
    .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
    .hold_bus_uninit = false,
    };

    err = nrfx_twim_init(&_m_twi, &config, _evt_handler, NULL);
    APP_ERROR_CHECK(err);

    NRF_P0->PIN_CNF[I2C_SCL_PIN] &= ~GPIO_PIN_CNF_DRIVE_Msk; // Clear the drive config
    NRF_P0->PIN_CNF[I2C_SCL_PIN] |= (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos); // Set the new drive config

    NRF_P0->PIN_CNF[I2C_SDA_PIN] &= ~GPIO_PIN_CNF_DRIVE_Msk; // Clear the drive config
    NRF_P0->PIN_CNF[I2C_SDA_PIN] |= (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos); // Set the new drive config

    I got 815kHz which is cool. I can't comment on power consumption yet though.

Related