AVR- RS232 capture with interrupt

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

AVR- RS232 capture with interrupt

Post by Niro »

Hello all,

I'm not very familiar with interrupt programming on the AVR. But I'm trying to capture incomming data on the rs232-port (PD0) with the 'UART0 RX'-interrupt on the ATMega168 and show the hex-value on the display, but nothing happens (Test-programm is attached).
Shouldn't the RXINT jump into the linked macro every time a new byte is comming from the PC and store it into my RxIN-variable? Should this also work on the simulator? Can I disable and enable the RXINT-interrupt by only adding the interrupt-symbol in the program as often as needed or do I have to add additional code?
I've already tried the 'TEST RS232 - TEST RECEPTION.fcf' example from the forum but this also doesn't work (I think this is for PIC).
Could you please give some help?

Many thanks,
Niro
RS232_IRQ_Test.fcf_avr
(10.5 KiB) Downloaded 302 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: AVR- RS232 capture with interrupt

Post by Benj »

Hello Niro,

Your program looks ok to me, Can you do the 1 second flasher test to ensure your AVR is not running with the /8 clock configuration enabled. Eg running at 0.5MHz rather then 4MHz.

One suggestion once you have this interrupt working would be to set a flag in the interrupt and then process the flag in your main and do the display routine. Otherwise you may miss interrupt signals while your servicing the LCD.

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: AVR- RS232 capture with interrupt

Post by Niro »

Hello Benj,

thanks for your help! Now the transmission works fine.
The interrupt-flag is a good suggestion. The shown IRQ-test programm is only a part of my complete RS232 data processing. I'm receiving/sending formated data-packages from 10...80 bytes including checksum.
One problem, if the data comes too fast, I may lose some bytes if the data processing takes too long. Than I can use the IRQ-flag to notice the problem and my send some error specific code to the PC.
The other problem is if the incomming data is too slow or even hangs (e.g. for more than 100ms), I need something like a timeout timer. Do you have any suggetions how to solve this in an easy way?

Thanks,
Niro

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: AVR- RS232 capture with interrupt

Post by Benj »

Hello Niro,

A timout can be done by using a while loop and a count variable. Before entering the loop reset the count variable to 0. when in the loop check for incoming data and if no data is present then increment the count. To come out of the while loop on a timeout you can just see if the count variable is above a certain threshold value.

eg,

count = 0
while counter < 200
{
listen for data
if data available
yes: count = 0
no: count = count + 1
}

Post Reply