ISR for USB to PC communication

Hi,

I'm trying to communicate with my arduino mega 2560 trough the serial monitor. Can you give me some tips on how to do this using interrupts?

Thanks

One of the best examples you will find is in the source code for the core. Search for "HardwareSerial.cpp" in the Arduino directory.

Thanks, will do.

I'm to read the code in the HardwareSerial.cpp but I'm not finding anything on interrupts....help!

All the functions at the top, like SIGNAL(USART_RX_vect)

I'm trying to communicate with my arduino mega 2560 trough the serial monitor. Can you give me some tips on how to do this using interrupts?

The serial monitor sends serial data to the Arduino. The arrival of data on the serial port triggers an interrupt. You do not have to do anything to handle this interrupt.

What is it you are trying to do?

Depending on the data sent to the board i want to trigger a series os events. The ISR routine just needs to read the data sent to a variable or array.

There is already an ISR to read serial data, and store it in a buffer, for the Serial.available()/Serial.read() methods to access.

I'm not seeing the need for you to write an interrupt service routine, nor an I seeing what would trigger that routine.

The thing is, if I put a Serial.read() inside the loop() basically it would try to read the serial port in each cycle. What i want is to use an interrupt to read the data in the serial port. That way a can store the data, say a char, in a variable and to what ever i want with it. I know that i don’t need interrupts to do that but its a much more efficient way to do it (i think).

In loop, or in the ISR, you would need to test whether there is a character to read. If there was, you would need to read that character, and store it somewhere.

Doing this in loop, there is no complexity of interrupt handlers.

Doing it in an ISR is not more efficient (you still have the same amount of work to do), and you have the need to define something to trigger the ISR. What that something is is what I am having difficulty understanding.

Using interrupt i don't need to test if theres a char to read because the ISR whenever theres activity in the serial port (receiver end). I know i can do this in the other serial ports (I'm using a arduino mega 2560) but I'm problems find a way to use interrupts on pin 0 (Rx0). I'm looking at the HardwareSerial.cpp but with no success so far. The efficiency I was talking about is in terms of processor usage. It reads the serial port only when data arrives, instead of testing it on each cycle.

The efficiency I was talking about is in terms of processor usage. It reads the serial port only when data arrives, instead of testing it on each cycle.

So how does an interrupt know something has arrived in the serial buffer without checking? Is there psyschic microcontroller activity in play?

It “fires” an interrupt each time theres activity in the Rx pin. But I think that beside the point in this case. What I want to do is replicate the interrupt behavior that, for example, Rx1 and Tx1 have.

The serial USART is already utilizing received character interrupts and handled by the standard serial library ISR. The USART received character interrupt can only be linked to one and only one ISR function. Are you proposing replacing the standard hardward serial library and ISR with your own library and ISR? If so just read and understand the HardwareSerial.cpp code and modify it to your requirements. Lefty

I just want to access the data received in the serial port each time the ISR is triggered.