0

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?

  • If you edited them in your local IDE installation then there's nothing to do. I don't quite understand your question - you edited the files, now you want to know what to do with them? They have been edited. If you saved the files after editing them (which you would have done) then what is it you are now hoping to do with them? – Majenko Jun 6 '16 at 11:27
  • I write a new file because i did´t find them in the local IDE. It will be nice when you have a path than i know what i have to do. – sniffi Jun 6 '16 at 11:34
  • 1
    Oh sorry i find it, in the link from Github is the path i didn´t see it the whole weekend sry that was my fail. – sniffi Jun 6 '16 at 11:41
  • I'd rename them to something new, and add them to the libraries folder. – Gerben Jun 6 '16 at 12:18
  • In Linux, after building the data base, "locate HardwareSerial.cpp" results in: /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp and several other hits. This works for Mac as well. If you are on a Windows machine, the search feature varies from version to version of Windows. And some implementations are very slow. If you can not find the file ... consider upgrading to the latest version of the Arduino IDE. – st2000 Jun 6 '16 at 12:29
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.