From 2105b8b06fef3e155dcdb775436ca1f77dccd586 Mon Sep 17 00:00:00 2001 From: Christoph Gommel Date: Sat, 24 Mar 2018 21:23:25 +0100 Subject: [PATCH] Update core_esp8266_si2c.c (#3389) With this patch the set up clock rate survives a re-init that is done by many libraries several times. This makes e.g. an accelerated OLED display possible with the adafruit libraries --- cores/esp8266/core_esp8266_si2c.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/core_esp8266_si2c.c b/cores/esp8266/core_esp8266_si2c.c index 54c17f2b7..784a546be 100644 --- a/cores/esp8266/core_esp8266_si2c.c +++ b/cores/esp8266/core_esp8266_si2c.c @@ -22,6 +22,7 @@ #include "pins_arduino.h" #include "wiring_private.h" +unsigned int preferred_si2c_clock = 100000; unsigned char twi_dcount = 18; static unsigned char twi_sda, twi_scl; static uint32_t twi_clockStretchLimit; @@ -44,6 +45,7 @@ static uint32_t twi_clockStretchLimit; #endif void twi_setClock(unsigned int freq){ + preferred_si2c_clock = freq; #if F_CPU == FCPU80 if(freq <= 50000) twi_dcount = 38;//about 50KHz else if(freq <= 100000) twi_dcount = 19;//about 100KHz @@ -72,7 +74,7 @@ void twi_init(unsigned char sda, unsigned char scl){ twi_scl = scl; pinMode(twi_sda, INPUT_PULLUP); pinMode(twi_scl, INPUT_PULLUP); - twi_setClock(100000); + twi_setClock(preferred_si2c_clock); twi_setClockStretchLimit(230); // default value is 230 uS } @@ -231,5 +233,6 @@ uint8_t twi_status() { if(!twi_write_start()) return I2C_SDA_HELD_LOW_AFTER_INIT; //line busy. SDA again held low by another device. 2nd master? - return I2C_OK; //all ok + return I2C_OK; //all ok + }