Go Down

Topic: Using Arduino Mega2560 Serial Port 0 (Read 106 times) previous topic - next topic

bastjan

Hi

Basically, I borrowed this code from a previous Uno project because I need it for a larger project.

Basically, I want to test the serial interrupt (TX) on the Mega.

So I connected the Arduino with the USB and downloaded the code. I opened the Serial Monitor and typed hello and sent it.  The TX LED flash, but I was expecting the built-in LED to  light up, since in the ISR I sent it high.

Can somone explain why the ISR is not being execute pls

Thanks   


void setup() {
 
                                               
 serialBegin();
 pinMode(LED_BUILTIN, OUTPUT);
                                             
}


void loop() {
 

}     

void serialBegin(void)
{
   
   sei(); // Enable Interrupt
   
   int baudrate=103;       // 9600
   UBRR0H = (baudrate>>8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
   UBRR0L = baudrate; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
   
   UCSR0B = (1 << RXEN0) | (1 << TXEN0);   // Turn on the transmission and reception circuitry
   UCSR0B |= (1 << TXCIE0); // enable RX interrupt
   
   UCSR0C =   (3 << UCSZ00) | (0<< USBS0); // Use 8-bit character frame and 1 stop bit (check data sheet pg 221)
     
}


  ISR(USART0_TXC_vect) // Read String
  {

  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
 

  }

pylon

Code: [Select]
  ISR(USART0_TXC_vect) // Read String

Shouldn't that be USART0_RXC_vect?

Robin2

It's always the fault of the little yellow guy with the dark glasses  :)

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

bastjan

because I am transmitting datq via the USB of the arduino

pylon

Quote
because I am transmitting datq via the USB of the arduino
You're transmitting data from the PC to the Arduino, right? So on the Arduino end it's receiving data. You don't have any code in your sketch that sends data out of the Arduino.

Go Up