diff --git a/hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp b/hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp index 87fd6dfbbe..bdcd457169 100644 --- a/hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp +++ b/hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp @@ -392,30 +392,34 @@ void uart_ignore_char(char c) { void uart0_write_char(char c) { if(&Serial != NULL && Serial.isTxEnabled()) { - if(c == '\n') { - Serial.write('\r'); - } - Serial.write(c); - } else { - if(c == '\n') { - USF(0) = '\r'; + if(Serial.availableForWrite() > 0) { + if(c == '\n') { + Serial.write('\r'); + } + Serial.write(c); + return; } - USF(0) = c; } + if(c == '\n') { + USF(0) = '\r'; + } + USF(0) = c; } void uart1_write_char(char c) { if(&Serial1 != NULL && Serial1.isTxEnabled()) { - if(c == '\n') { - Serial1.write('\r'); - } - Serial1.write(c); - } else { - if(c == '\n') { - USF(1) = '\r'; + if(Serial1.availableForWrite() > 0) { + if(c == '\n') { + Serial1.write('\r'); + } + Serial1.write(c); + return; } - USF(1) = c; } + if(c == '\n') { + USF(1) = '\r'; + } + USF(1) = c; } static int s_uart_debug_nr = UART0; diff --git a/hardware/esp8266com/esp8266/libraries/SPI/SPI.cpp b/hardware/esp8266com/esp8266/libraries/SPI/SPI.cpp index c96c4fcb82..7d52528ef1 100644 --- a/hardware/esp8266com/esp8266/libraries/SPI/SPI.cpp +++ b/hardware/esp8266com/esp8266/libraries/SPI/SPI.cpp @@ -121,14 +121,14 @@ void SPIClass::setBitOrder(uint8_t bitOrder) { * @return */ static uint32_t ClkRegToFreq(spiClk_t * reg) { - return (F_CPU / ((reg->regPre + 1) * (reg->regN + 1))); + return (SPI_MAX_SPEED / ((reg->regPre + 1) * (reg->regN + 1))); } void SPIClass::setFrequency(uint32_t freq) { static uint32_t lastSetFrequency = 0; static uint32_t lastSetRegister = 0; - if(freq >= F_CPU) { + if(freq >= SPI_MAX_SPEED) { setClockDivider(0x80000000); return; } @@ -164,7 +164,7 @@ void SPIClass::setFrequency(uint32_t freq) { reg.regN = calN; while(calPreVari++ <= 1) { // test different variants for Pre (we calculate in int so we miss the decimals, testing is the easyest and fastest way) - calPre = (((F_CPU / (reg.regN + 1)) / freq) - 1) + calPreVari; + calPre = (((SPI_MAX_SPEED / (reg.regN + 1)) / freq) - 1) + calPreVari; if(calPre > 0x1FFF) { reg.regPre = 0x1FFF; // 8191 } else if(calPre <= 0) { diff --git a/hardware/esp8266com/esp8266/libraries/SPI/SPI.h b/hardware/esp8266com/esp8266/libraries/SPI/SPI.h index e67b5b0d58..68d2a3dc6c 100644 --- a/hardware/esp8266com/esp8266/libraries/SPI/SPI.h +++ b/hardware/esp8266com/esp8266/libraries/SPI/SPI.h @@ -45,6 +45,8 @@ #define SPI_CLOCK_DIV64 0x04fc1001 //250 KHz #endif +#define SPI_MAX_SPEED (80000000L) + const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0 const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1 const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0