I changed 2 Arduino Libraries because i have a 9 bit data protocol, now i want use the amended Libraries on my Arduino mega2560.
At first i have set a 9 bit data mode that can i do when i set the UCSZ12 bit on 1(original code under the following link: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp#L103 ):
void HardwareSerial::begin(unsigned long baud, byte config)
...
sbi(*_ucsrb, RXCIE0);
sbi(*_ucsrb, UCSZ12); // chance: set 9-bit data mode on 1
cbi(*_ucsrb, UDRIE0);
...
At second i want throw an interrupt when the 9th bit is an 1 that can i do when i change the code like the follow (original code under the following link : https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial_private.h#L101 ):
void HardwareSerial::_rx_complete_irq(void)
if (bit_is_clear(*_ucsra, UPE0)) {
bool is_address = UCSR0B & _BV(RXB80);
unsigned char c = *_udr;
if (is_address) {
do_something_with_address(c);
return;
}
rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
...
What must i do with the two file ́s?
How can i use the changed Libraries?
1 Answer 1
I found the path to the files i want change in the github link so i can change the files(C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino).
I enable the uart for 9 bit, i add sbi(*_ucsrb, UCSZ12); in HardwareSerial::begin
I decided that i only send a Flag to my PC when the 9th bit is set. For that i change the _rx_buffer to a 2 byte matrix (short _rx_buffer). Now i send the databyte in the low-byte and flags for 9 bit, framing error and overrun error in the high-byte. That i can do that i change the void HardwareSerial::_rx_complete_irq(void) code like the follow:
void HardwareSerial::_rx_complete_irq(void)
{
if (bit_is_clear(*_ucsra, UPE0))
{
bool is_address = UCSR0B & _BV(RXB80);
bool is_framError = UCSR0A & _BV(FE0);
bool is_overError = UCSR0A & _BV(DOR0);
unsigned char c = *_udr;
rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
if (i != _rx_buffer_tail)
{
_rx_buffer[_rx_buffer_head] = c;
_rx_buffer[_rx_buffer_head] |= is_address << 8;
_rx_buffer[_rx_buffer_head] |= is_framError << 9;
_rx_buffer[_rx_buffer_head] |= is_overError << 10;
_rx_buffer_head = i;
}
}
else { *_udr; };
}
I hope this will work and i can evaluate the data right at the PC.
Frindly wishes sniffi
libraries
folder.