Skip to content

Commit 2105b8b

Browse files
cgommeldevyte
authored andcommitted
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
1 parent 6464ae0 commit 2105b8b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: cores/esp8266/core_esp8266_si2c.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "pins_arduino.h"
2323
#include "wiring_private.h"
2424

25+
unsigned int preferred_si2c_clock = 100000;
2526
unsigned char twi_dcount = 18;
2627
static unsigned char twi_sda, twi_scl;
2728
static uint32_t twi_clockStretchLimit;
@@ -44,6 +45,7 @@ static uint32_t twi_clockStretchLimit;
4445
#endif
4546

4647
void twi_setClock(unsigned int freq){
48+
preferred_si2c_clock = freq;
4749
#if F_CPU == FCPU80
4850
if(freq <= 50000) twi_dcount = 38;//about 50KHz
4951
else if(freq <= 100000) twi_dcount = 19;//about 100KHz
@@ -72,7 +74,7 @@ void twi_init(unsigned char sda, unsigned char scl){
7274
twi_scl = scl;
7375
pinMode(twi_sda, INPUT_PULLUP);
7476
pinMode(twi_scl, INPUT_PULLUP);
75-
twi_setClock(100000);
77+
twi_setClock(preferred_si2c_clock);
7678
twi_setClockStretchLimit(230); // default value is 230 uS
7779
}
7880

@@ -231,5 +233,6 @@ uint8_t twi_status() {
231233
if(!twi_write_start())
232234
return I2C_SDA_HELD_LOW_AFTER_INIT; //line busy. SDA again held low by another device. 2nd master?
233235

234-
return I2C_OK; //all ok
236+
return I2C_OK; //all ok
237+
235238
}

0 commit comments

Comments
 (0)