[solved] I2C speed to 400KHz ... HowTo?

Hi.

I am trying to setup ATmega 2560 (Arduino Mega) I2C comms to 400Khz.

The message is displayed but PulseView (1Mhz sample rate) says it remains at 100KHz.

Thanks for help
Martins

#include <Wire.h>
#include "LiquidCrystal_I2C.h"

LiquidCrystal_I2C lcd(0x3f, 20,4);

void setup() {
  lcd.init();
  Wire.setClock(400000);
  lcd.backlight();
  lcd.print("Helo World");
}

void loop() {

}

I also tried this:

void setup() {
  Wire.setClock(400000);
  lcd.init();
  lcd.backlight();
  lcd.print("Helo World");
}

The Wire.begin() sets the default of 100kHz. The normal sequence of functions is:

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

(the compiler defaults to integer and the 400000 is a large number, so I add 'UL' to the number to tell the compiler that it is a 'Unsigned Long' number)

There is a Wire.begin() in the lcd.init() function, so it should run at 400kHz. I don't know what is going on.

Which "LiquidCrystal_I2C" library do you use ? There are many libraries with that name.
There are delays in the library, can you show a screendump to prove that it is 100kHz ?

I don't know where my I2C LCD display is, so I can't test it right now. Sorry.

Which logic analyzer do you have ? The 2MHz is low to capture a 400kHz signal. For the LHT00SU1, you have to turn off the analog channel in PulseView to be able to set the sample rate higher for digital inputs.

I'll do a couple more testes, meanwhile please see the picture below.

Koepel:
(the compiler defaults to integer and the 400000 is a large number, so I add 'UL' to the number to tell the compiler that it is a 'Unsigned Long' number)

Does it imply that the I2C bus will be running at 6784 Hz (0x6 1A80) if the argument/operand is not qualified by UL?

Your picture:

I am using this library:

Ok. This works:

  lcd.init();
  Wire.setClock(400000);

Works with and without UL.

I didn't try Wire.setClock(400000) before lcd.init() because I thought it would interfere with something already going on, but I was alerted when you said:

There is a Wire.begin() in the lcd.init() function

Thank you.
Martins

GolamMostafa:
Does it imply that the I2C bus will be running at 6784 Hz (0x6 1A80) if the argument/operand is not qualified by UL?

No. The “UL” is superfluous here.

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