mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
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
This commit is contained in:
parent
6464ae0c79
commit
2105b8b06f
@ -22,6 +22,7 @@
|
|||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
#include "wiring_private.h"
|
#include "wiring_private.h"
|
||||||
|
|
||||||
|
unsigned int preferred_si2c_clock = 100000;
|
||||||
unsigned char twi_dcount = 18;
|
unsigned char twi_dcount = 18;
|
||||||
static unsigned char twi_sda, twi_scl;
|
static unsigned char twi_sda, twi_scl;
|
||||||
static uint32_t twi_clockStretchLimit;
|
static uint32_t twi_clockStretchLimit;
|
||||||
@ -44,6 +45,7 @@ static uint32_t twi_clockStretchLimit;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void twi_setClock(unsigned int freq){
|
void twi_setClock(unsigned int freq){
|
||||||
|
preferred_si2c_clock = freq;
|
||||||
#if F_CPU == FCPU80
|
#if F_CPU == FCPU80
|
||||||
if(freq <= 50000) twi_dcount = 38;//about 50KHz
|
if(freq <= 50000) twi_dcount = 38;//about 50KHz
|
||||||
else if(freq <= 100000) twi_dcount = 19;//about 100KHz
|
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;
|
twi_scl = scl;
|
||||||
pinMode(twi_sda, INPUT_PULLUP);
|
pinMode(twi_sda, INPUT_PULLUP);
|
||||||
pinMode(twi_scl, INPUT_PULLUP);
|
pinMode(twi_scl, INPUT_PULLUP);
|
||||||
twi_setClock(100000);
|
twi_setClock(preferred_si2c_clock);
|
||||||
twi_setClockStretchLimit(230); // default value is 230 uS
|
twi_setClockStretchLimit(230); // default value is 230 uS
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,5 +233,6 @@ uint8_t twi_status() {
|
|||||||
if(!twi_write_start())
|
if(!twi_write_start())
|
||||||
return I2C_SDA_HELD_LOW_AFTER_INIT; //line busy. SDA again held low by another device. 2nd master?
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user