Hi,
I'm experimenting a bit with using 9 bit serial using an Arduino Leonardo and IDE 1.8.3.
This is the code I have put together to test:
#include <SoftwareSerial.h>
#define BAUD 9600
SoftwareSerial mySerial(3, 4); // RX, TX
uint8_t n=0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(BAUD);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
//Serial1.begin(BAUD); //was used before replacement of files
Serial1.begin(BAUD,true); //9 bit mode (used after replacement of hardware serial files)
mySerial.begin(BAUD);
Serial.println("READY!");
}
void loop() {
uint16_t indata=0;
n = (n+1)%255;
Serial.print("SS TX = ");
if(n<=0x0F) Serial.print("0x0");
else Serial.print("0x");
Serial.print(n,HEX);
mySerial.write(n);
Serial.print(", S1 RX = ");
while(Serial1.available()>0){
indata = Serial1.read();
if(indata<=0x000F) Serial.print("0x000");
else if(indata<=0x00FF) Serial.print("0x00");
else if(indata<=0x0FFF) Serial.print("0x0");
else Serial.print("0x");
Serial.println(indata,HEX);
}
delay(500);
}
I ran it before replacing the libraries and it compiled and worked fine.
I then replaced the libraries with those from Nick's post (Mods to HardwareSerial to handle 9-bit data - Libraries - Arduino Forum) and now I am running into the following errors:
In file included from C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:30:0:
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial_private.h: In member function 'void HardwareSerial::_rx_complete_irq()':
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial_private.h:109:38: error: 'RXB80' was not declared in this scope
unsigned int c = (*_ucsrb & bit (RXB80)) << 7; // get the 9th bit (it's already shifted over one)
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\Arduino.h:123:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial_private.h:123:38: error: 'RXB80' was not declared in this scope
unsigned int c = (*_ucsrb & bit (RXB80)) << 7; // get the 9th bit (it's already shifted over one)
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial_private.h:123:33: note: in expansion of macro 'bit'
unsigned int c = (*_ucsrb & bit (RXB80)) << 7; // get the 9th bit (it's already shifted over one)
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp: In member function 'void HardwareSerial::_tx_udr_empty_irq()':
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:90:21: error: 'TXB80' was not declared in this scope
*_ucsrb |= bit (TXB80); // set 9th bit
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\Arduino.h:123:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:92:22: error: 'TXB80' was not declared in this scope
*_ucsrb &= ~bit (TXB80); // clear 9th bit
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\Arduino.h:123:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp: In member function 'size_t HardwareSerial::write9bit(uint16_t)':
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:237:23: error: 'TXB80' was not declared in this scope
*_ucsrb |= bit (TXB80); // set 9th bit
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\Arduino.h:123:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:239:24: error: 'TXB80' was not declared in this scope
*_ucsrb &= ~bit (TXB80); // clear 9th bit
^
C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\cores\arduino\Arduino.h:123:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
Using library SoftwareSerial at version 1.0 in folder: C:\Users\Diag 1\Downloads\Arduino v1.8.5\hardware\arduino\avr\libraries\SoftwareSerial
exit status 1
Error compiling for board Arduino Leonardo.
Can somebody please help me understand why I am getting those errors an how to fix them. Thanks.