void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms) { if(0 > _uart_nr || _uart_nr > 2) { log_e("Serial number is invalid, please use 0, 1 or 2"); return; } if(_uart) { end(); } if(_uart_nr == 0 && rxPin < 0 && txPin < 0) { rxPin = 3; txPin = 1; } if(_uart_nr == 1 && rxPin < 0 && txPin < 0) { rxPin = RX1; txPin = TX1; } if(_uart_nr == 2 && rxPin < 0 && txPin < 0) { rxPin = RX2; txPin = TX2; } _uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert); if(!baud) { time_t startMillis = millis(); unsigned long detectedBaudRate = 0; while(millis() - startMillis < timeout_ms && !(detectedBaudRate = uartDetectBaudrate(_uart))) { yield(); } end(); if(detectedBaudRate) { delay(100); // Give some time... _uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, 256, invert); } else { log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible"); _uart = NULL; } } }
int main(void) { //Start the Uart Communication with 9600 Baud with 2 Stop Bits uartBegin(9600); //Reference Voltage as AVcc with external capacitor on Aref ADMUX |= (1<<REFS0); //Enable the ADC Interrupt Enalbe ADCSRA |= (1<<ADIE); //Set the Prescalar to 128 ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); //Enable the ADC Enable to start the ADC Converstion ADCSRA |= (1<<ADEN); //Enalbe the Global Interrupt sei(); //Reads the changes in the Pin and updates the Register ADCSRA |= (1<<ADSC); while(1); }