I'm trying to send data from memory out using the Uart on a pro mini.
In order to set the baud, parity and stop bits - Serial.begin is used. So I've tried to follow the trial through to the source code, but I can't fathom how the code suddenly uses the function HardwareSerial::begin to implement those values in the registers. Looked through all the Arduino headers and can't see the definitions switch from one to the other name anywhere.
Thanks if you can help here.
You mean Serial, Serial1, Serial2?
#if defined(UBRRH) || defined(UBRR0H)
extern HardwareSerial Serial;
#elif defined(USBCON)
#include "USBAPI.h"
// extern HardwareSerial Serial_;
#endif
#if defined(UBRR1H)
extern HardwareSerial Serial1;
#endif
#if defined(UBRR2H)
extern HardwareSerial Serial2;
#endif
#if defined(UBRR3H)
extern HardwareSerial Serial3;
#endif
In the source file all the registers are set for the Serial variables.
#if defined(UBRRH) && defined(UBRRL)
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X);
#elif defined(UBRR0H) && defined(UBRR0L)
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0);
#elif defined(USBCON)
// do nothing - Serial object and buffers are initialized in CDC code
#else
#error no serial port defined (port 0)
#endif
#if defined(UBRR1H)
HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1);
#endif
#if defined(UBRR2H)
HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2);
#endif
#if defined(UBRR3H)
HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
#endif
Ok, thanks. I'm going to have a close look at those lines of code.
The baud rate and parity and stop values are being passed on to the hardware specific code at that point in a way I don't quite grasp. There are more variables than can be entered in Serial.begin(baud,parity,stop).
I don't understand the space in HardwareSerial Serial (.. how does the syntax get the values from Serial.begin.
It may be a steep learning curve at this point but easier in the long run. I don't need to re-write a complete flexible printer library for a Custom s'print-S thermal printer, just make sure I have the communication correct before sending control codes for a graphic print mode and 8 bit data to it.
Many thanks anyway and I'll keep on trying to figure it out.