1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-27 21:16:50 +03:00

Merge pull request #22 from Links2004/esp8266

pull SPI speed fix and uart overflow
This commit is contained in:
ficeto 2015-05-16 12:26:11 +03:00
commit 9217187968
3 changed files with 25 additions and 19 deletions

View File

@ -392,31 +392,35 @@ void uart_ignore_char(char c) {
void uart0_write_char(char c) { void uart0_write_char(char c) {
if(&Serial != NULL && Serial.isTxEnabled()) { if(&Serial != NULL && Serial.isTxEnabled()) {
if(Serial.availableForWrite() > 0) {
if(c == '\n') { if(c == '\n') {
Serial.write('\r'); Serial.write('\r');
} }
Serial.write(c); Serial.write(c);
} else { return;
}
}
if(c == '\n') { if(c == '\n') {
USF(0) = '\r'; USF(0) = '\r';
} }
USF(0) = c; USF(0) = c;
} }
}
void uart1_write_char(char c) { void uart1_write_char(char c) {
if(&Serial1 != NULL && Serial1.isTxEnabled()) { if(&Serial1 != NULL && Serial1.isTxEnabled()) {
if(Serial1.availableForWrite() > 0) {
if(c == '\n') { if(c == '\n') {
Serial1.write('\r'); Serial1.write('\r');
} }
Serial1.write(c); Serial1.write(c);
} else { return;
}
}
if(c == '\n') { if(c == '\n') {
USF(1) = '\r'; USF(1) = '\r';
} }
USF(1) = c; USF(1) = c;
} }
}
static int s_uart_debug_nr = UART0; static int s_uart_debug_nr = UART0;

View File

@ -121,14 +121,14 @@ void SPIClass::setBitOrder(uint8_t bitOrder) {
* @return * @return
*/ */
static uint32_t ClkRegToFreq(spiClk_t * reg) { 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) { void SPIClass::setFrequency(uint32_t freq) {
static uint32_t lastSetFrequency = 0; static uint32_t lastSetFrequency = 0;
static uint32_t lastSetRegister = 0; static uint32_t lastSetRegister = 0;
if(freq >= F_CPU) { if(freq >= SPI_MAX_SPEED) {
setClockDivider(0x80000000); setClockDivider(0x80000000);
return; return;
} }
@ -164,7 +164,7 @@ void SPIClass::setFrequency(uint32_t freq) {
reg.regN = calN; 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) 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) { if(calPre > 0x1FFF) {
reg.regPre = 0x1FFF; // 8191 reg.regPre = 0x1FFF; // 8191
} else if(calPre <= 0) { } else if(calPre <= 0) {

View File

@ -45,6 +45,8 @@
#define SPI_CLOCK_DIV64 0x04fc1001 //250 KHz #define SPI_CLOCK_DIV64 0x04fc1001 //250 KHz
#endif #endif
#define SPI_MAX_SPEED (80000000L)
const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0 const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0
const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1 const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1
const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0 const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0