Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 646a94c

Browse files
committed
Merge pull request #117 from thomasfla/esp8266
HardwareSerial: add other configs than 8N1
2 parents c855c53 + be5f1f8 commit 646a94c

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

‎README.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ more than 20 milliseconds is not recommended.
6262

6363
```Serial``` object works much the same way as on a regular Arduino. Apart from hardware FIFO (128 bytes for TX and RX) HardwareSerial has additional 256-byte TX and RX buffers. Both transmit and receive is interrupt-driven. Write and read functions only block the sketch execution when the respective FIFO/buffers are full/empty.
6464

65-
Only 8n1 mode is supported right now.
66-
6765
By default the diagnostic output from WiFi libraries is disabled when you call ```Serial.begin```. To enable debug output again, call ```Serial.setDebugOutput(true);```
6866

6967
#### WiFi(ESP8266WiFi library) ####

‎cores/esp8266/HardwareSerial.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
2121
Modified 31 March 2015 by Markus Sattler (rewrite the code for UART0 + UART1 support in ESP8266)
22-
22+
Modified 25 April 2015 by Thomas Flayols (add configuration different from 8N1 in ESP8266)
2323
*/
2424

2525
#include <stdlib.h>
@@ -86,7 +86,7 @@ void uart_disarm_tx_interrupt(uart_t* uart);
8686
void uart_set_baudrate(uart_t* uart, int baud_rate);
8787
int uart_get_baudrate(uart_t* uart);
8888

89-
uart_t* uart_init(UARTnr_t uart_nr, int baudrate);
89+
uart_t* uart_init(UARTnr_t uart_nr, int baudrate, byte config);
9090
void uart_uninit(uart_t* uart);
9191
void uart_swap(uart_t* uart);
9292

@@ -278,7 +278,7 @@ int ICACHE_FLASH_ATTR uart_get_baudrate(uart_t* uart) {
278278
return uart->baud_rate;
279279
}
280280

281-
uart_t* ICACHE_FLASH_ATTR uart_init(UARTnr_t uart_nr, int baudrate) {
281+
uart_t* ICACHE_FLASH_ATTR uart_init(UARTnr_t uart_nr, int baudrate, byte config) {
282282

283283
uint32_t conf1 = 0x00000000;
284284
uart_t* uart = (uart_t*) os_malloc(sizeof(uart_t));
@@ -314,7 +314,7 @@ uart_t* ICACHE_FLASH_ATTR uart_init(UARTnr_t uart_nr, int baudrate) {
314314
break;
315315
}
316316
uart_set_baudrate(uart, baudrate);
317-
WRITE_PERI_REG(UART_CONF0(uart->uart_nr), 0x3 << UART_BIT_NUM_S); // 8n1
317+
WRITE_PERI_REG(UART_CONF0(uart->uart_nr), config);
318318

319319
uart_flush(uart);
320320
uart_interrupt_enable(uart);
@@ -493,7 +493,7 @@ void ICACHE_FLASH_ATTR HardwareSerial::begin(unsigned long baud, byte config) {
493493
uart_set_debug(UART_NO);
494494
}
495495

496-
_uart = uart_init(_uart_nr, baud);
496+
_uart = uart_init(_uart_nr, baud, config);
497497

498498
if(_uart == 0) {
499499
return;

‎cores/esp8266/HardwareSerial.h‎

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Modified 3 December 2013 by Matthijs Kooijman
2222
Modified 18 December 2014 by Ivan Grokhotkov (esp8266 platform support)
2323
Modified 31 March 2015 by Markus Sattler (rewrite the code for UART0 + UART1 support in ESP8266)
24+
Modified 25 April 2015 by Thomas Flayols (add configuration different from 8N1 in ESP8266)
2425
*/
2526

2627
#ifndef HardwareSerial_h
@@ -33,31 +34,31 @@
3334
#define SERIAL_TX_BUFFER_SIZE 256
3435
#define SERIAL_RX_BUFFER_SIZE 256
3536

36-
// // Define config for Serial.begin(baud, config);
37-
//#define SERIAL_5N1 0x00
38-
//#define SERIAL_6N1 0x02
39-
//#define SERIAL_7N1 0x04
40-
//#define SERIAL_8N1 0x06
41-
//#define SERIAL_5N2 0x08
42-
//#define SERIAL_6N2 0x0A
43-
//#define SERIAL_7N2 0x0C
44-
//#define SERIAL_8N2 0x0E
45-
//#define SERIAL_5E1 0x20
46-
//#define SERIAL_6E1 0x22
47-
//#define SERIAL_7E1 0x24
48-
//#define SERIAL_8E1 0x26
49-
//#define SERIAL_5E2 0x28
50-
//#define SERIAL_6E2 0x2A
51-
//#define SERIAL_7E2 0x2C
52-
//#define SERIAL_8E2 0x2E
53-
//#define SERIAL_5O1 0x30
54-
//#define SERIAL_6O1 0x32
55-
//#define SERIAL_7O1 0x34
56-
//#define SERIAL_8O1 0x36
57-
//#define SERIAL_5O2 0x38
58-
//#define SERIAL_6O2 0x3A
59-
//#define SERIAL_7O2 0x3C
60-
//#define SERIAL_8O2 0x3E
37+
// Define config for Serial.begin(baud, config);
38+
#define SERIAL_5N1 0x10
39+
#define SERIAL_6N1 0x14
40+
#define SERIAL_7N1 0x18
41+
#define SERIAL_8N1 0x1c
42+
#define SERIAL_5N2 0x30
43+
#define SERIAL_6N2 0x34
44+
#define SERIAL_7N2 0x38
45+
#define SERIAL_8N2 0x3c
46+
#define SERIAL_5E1 0x12
47+
#define SERIAL_6E1 0x16
48+
#define SERIAL_7E1 0x1a
49+
#define SERIAL_8E1 0x1e
50+
#define SERIAL_5E2 0x32
51+
#define SERIAL_6E2 0x36
52+
#define SERIAL_7E2 0x3a
53+
#define SERIAL_8E2 0x3e
54+
#define SERIAL_5O1 0x13
55+
#define SERIAL_6O1 0x17
56+
#define SERIAL_7O1 0x1b
57+
#define SERIAL_8O1 0x1f
58+
#define SERIAL_5O2 0x33
59+
#define SERIAL_6O2 0x37
60+
#define SERIAL_7O2 0x3b
61+
#define SERIAL_8O2 0x3f
6162

6263
class cbuf;
6364

@@ -79,7 +80,7 @@ class HardwareSerial: public Stream {
7980
HardwareSerial(UARTnr_t uart_nr);
8081

8182
void begin(unsigned long baud) {
82-
begin(baud, 0);
83+
begin(baud, SERIAL_8N1);
8384
}
8485
void begin(unsigned long, uint8_t);
8586
void end();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /