Understanding ISR -routines.....

HI

In the article Serial - Interrupt - Syntax & Programs - Arduino Forum user MEM writes this: (#2)

"
Re: Serial - Interrupt
#1
Sep 22, 2008, 04:19 pm Last Edit: Sep 22, 2008, 04:21 pm by mem Reason: 1
I doubt you will want to do that. The serial data is captured using an interrupt to put each character into the serial input buffer. If you add any additional processing to that interrupt or trigger another interrupt then you may lose incoming characters because the arduino disables interrupts when it is in an interrupt handler.

Perhaps if you say a little about what you want your application to do, you can get some suggestions on how to handle serial data while the sketch is also processing some other tasks.

"

Sorry for asking, but I need to have this really nailed (7 inches nails ) .

Does this means, that every time when we Use the Serial.___ GET CHAR (not af function, merely a general name of ALL functions getting a Serial char from the serial port) we DO an Interrupt and the software handles the ISR-routine. ? (So we, as users, don't have to worry about the details).

And IF we write our own SERIAL.ISR we do the Interrupt twice ? (pretty stupid, btw) .

And last question, If I want to use the built-in Interrupt, how do I get the Data from the RX-register, reset the Interrupt flag(s) (if more than one) ?

I plan to build a system consisting of one 2560 Mega interfacing 2 AT328P Uc's. (NOT UNO's but pure AT328P UC's).

2650/ Serial(0) is used by the Computer / USB interface.

2650/Serial1 will be used for commands/answers to/from AT328P(1 / serial) and the second At328P (2650/ serial2) will be used as a system hardware Monitor. Using serial for programming and Interrupt.

IF a severe hardware error occur (AT328(1) + 2560 peripherals) the 328P(2) fires a serial interrupt to the 2560, forcing a close-down of the peripheral(s) on the relevant Uc. Eventually ALL peripherals depending on Error-code.

Using POLL here will not be an option . !

Kris

Does this means, that every time when we Use the Serial.___ GET CHAR (not af function, merely a general name of ALL functions getting a Serial char from the serial port) we DO an Interrupt and the software handles the ISR-routine. ? (So we, as users, don't have to worry about the details).

No. The arrival of serial data triggers an interrupt. The interrupt handler collects the bits and assembles them in a byte, and puts the byte in the incoming buffer.

When you read the next character, no interrupts are involved.

And IF we write our own SERIAL.ISR we do the Interrupt twice ? (pretty stupid, btw) .

If you are using the hardware serial class, you can not write your own interrupt service routine, because the interrupt vector already has a handler registered.

Using POLL here will not be an option . !

It will be, because you have no other option. Write non-blocking code, so you can poll often.

HI,

Thanks a lot =

for( int a = 10; a < 20000000000000000000000000000000000000000000000000020; a = a + 1 )
{
Serial.Write ('Thank YOU ');
}

Now I got it.

And better yet: I know how to deal with it.

Kris

snestrup2000:
2650/Serial1 will be used for commands/answers to/from AT328P(1 / serial) and the second At328P (2650/ serial2) will be used as a system hardware Monitor. Using serial for programming and Interrupt.

IF a severe hardware error occur (AT328(1) + 2560 peripherals) the 328P(2) fires a serial interrupt to the 2560, forcing a close-down of the peripheral(s) on the relevant Uc. Eventually ALL peripherals depending on Error-code.

Using POLL here will not be an option . !

I don't understand this or why you conclude that polling is unsuitable?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

As long as you read data from the Serial input buffer before it can fill up there will be no data lost. You have not said what baud rate you will be using. However even at 500,000 baud I have no problems with my programs.

...R

   for( int a = 10; a < 20000000000000000000000000000000000000000000000000020; a = a + 1 ) 
  {
      Serial.Write ('Thank YOU '); 
  }

You could have at least made sure that your Thank YOU program worked :slight_smile:

HI,

#ROBIN2

You wrote

I don't understand this or why you conclude that polling is unsuitable?

In a way you are right. And I might be wrong.

But my experiences so far with hardware serial ports on PC's UARTS, Z-80 SIO's has been that using Interrups are faster (not always easier).

"Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. "

You (bet) I will ...

#UKHeliBob

You wrote:
"

Re: Understanding ISR -routines.....
#4
Today at 09:40 am
Code: [Select]

for( int a = 10; a < 20000000000000000000000000000000000000000000000000020; a = a + 1 )
{
Serial.Write ('Thank YOU ');
}

You could have at least made sure that your Thank YOU program worked :slight_smile:

"

DARN, you got me....

Here's a new example :

for( int a = 10; a < 20000000000000000000000000000000000000000000000000020; a = a + 1 )
{
Serial.write (" Thank YOU for Correcting me !!! "); // Write -> write ; ' -> "
}

(hehe and :slight_smile: !)!

Kris