Giter Club home page Giter Club logo

Comments (8)

greiman avatar greiman commented on May 18, 2024 1

I will add a call to set the I2C speed. This is the function from the Wire library.

void twi_setFrequency(uint32_t frequency)
{
  TWBR = ((F_CPU / frequency) - 16) / 2;
  
  /* twi bit rate formula from atmega128 manual pg 204
  SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
  note: TWBR should be 10 or higher for master mode
  It is 72 for a 16mhz Wiring board with 100kHz TWI */
}

The comment implies this works from about 40 kHz to 444,000 kHz with FCPU = 16 MHz.

from ssd1306ascii.

greiman avatar greiman commented on May 18, 2024 1

The above function works on any AVR board without including Wire.

To set 100 kHz on a 16 MHz AVR board you can just add a line like this.

TWBR = 72;

I have added a setClock() call to the AvrI2c so you will be able do the following in the next version of SSD1306AsciiAvrI2c.

oled.setI2cClock(100000L);

from ssd1306ascii.

deladriere avatar deladriere commented on May 18, 2024

I just do :
Wire.setClock(2500000L);
to change the i2c speed to my favorite speed (Yes I need High speed)

from ssd1306ascii.

MasterBlatter avatar MasterBlatter commented on May 18, 2024

KK but I'm not using Wire, just SSD1306Ascii and SSD1306AsciiAvrI2c

from ssd1306ascii.

deladriere avatar deladriere commented on May 18, 2024

@greiman
will
oled.setI2cClock(100000L);
affects communication with my other I2c devices too or just the SSD1306 ?
I want to use different speeds for my various slower devices. Today I speed up the clock when talking to the SSD1306 and reduce the speed just after to allow my other devices to work

from ssd1306ascii.

greiman avatar greiman commented on May 18, 2024

deladriere
Changing the I2C frequency on an AVR board is global. There is a single TWBR baud rate register. You must set the I2C frequency in your program before using a device.

MasterBlatter
I published an update that allows setting the I2C frequency with AvrI2c.

There are two methods.
You can change the default frequency by editing SSD1306Ascii.h.

/** AvrI2c uses 400 kHz fast mode if AVRI2C_FASTMODE is nonzero else 100 kHz. */
#define AVRI2C_FASTMODE 1

You can call oled.setI2cClock(frequency) in your sketch.

from ssd1306ascii.

deladriere avatar deladriere commented on May 18, 2024

@greiman
Thanks for the update
My board is a SAMD21 clone and I cannot have a global change of speed because my other device is slower than the display.
So I guess I'll stay with Wire.setClock(high-speed); before driving any SSD1306 command and Wire.setClock(low-speed); just after them

from ssd1306ascii.

greiman avatar greiman commented on May 18, 2024

deladriere

I guess this is a universal problem for Wire on all boards.

Too bad the Wire library is not like SPI. The SPI beginTransaction() protocol insures each device uses the proper clock.

from ssd1306ascii.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.