simulavr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Simulavr-devel] UART Interrupt and Timer problem


From: Jakob Schwendner
Subject: Re: [Simulavr-devel] UART Interrupt and Timer problem
Date: Wed, 11 May 2005 09:56:47 +1000

Hi Klaus,

thanks very much for you quick response. Yes, I am talking simulavrxx.
Sorry for the F_CPU and global.h, I was in a little hurry when I
prepared the test. The global.h only contained the F_CPU definition.
The problem I am having is that the TXC vector gets called so often,
where I think it shouldn't. I am very sorry, maybe there is something
fundamental that I haven't understood about avr interrupts, but I
thought the test program should behave as follows:
- setup the uart1
loop:
- Delay about 60000 cycles
- write a byte to UDR1
- byte gets written to serial pin
- TXC interrupt is raised
- TXC interrupt is cleared
- TXC vector gets called

The problem I am having is that I think after the first time the TXC
interrupt is raised it keeps calling the vector.
It does
- delay
- write udr1
- raise TXC
- call TXC vec
- call TXC vec
- call TXC vec
- call TXC vec
...

where it should behave like
- delay
- write udr1
- raise TXC
- call TXC vec
- delay
- write udr1
- raise TXC
- call TXC vec
- delay
...

Sorry for this awfully complicated way of explaining. I guess my point
is that the TXC vector gets called repeatidly where I think it should
only be called once.

Also have you got any idea why I would need to set the baud on the
serialrx class to 2*baud in the device? (like the device is set up for
19200, yet the serialrx class needs to be
38400 for it to work)

Thanks very much for all your help. Really appreciated. You've done a
great job on the simulavrxx anyway.

cheers,

Jakob

On 5/10/05, Klaus Rudolph <address@hidden> wrote:
> Hi Jakob,
> 
> I hope we are talking about simulavrxx :-)
> 
> I tried to reproduce your problem:
> first I have to remove the global.h file which I not have.
> next was setting F_CPU to 16000000.
> After that I tested the application with:
> simulavr -datmega128 -f uartproblem -t /dev/stdout
> 
> I saw that the vector for TXC was called a lot and the irq handler
> was executed as expected. After raising the irq the irq was cleared
> before calling the irq handler itself which is correct.
> The volatile variable was also written correct and no other problems
> comes up.
> 
> There are a lot of "IrqFlagCleared Vec:4" which seems a bit misterious,
> but this is correct because the TXD-Pin is on the same port like the
> external IRQ pins
> for the device so the check runs also for the complete port and
> the mode for the ext irq is set to 0 for each pin and this means
> if the pin is 0 the irq must be cleared. That is also done and
> traced out. This is not nice and I maybe change the message so that
> only the first "irqClear" is monitored.
> 
> If the problem still exist please ask again! Maybe I have done something
> different.
> 
> Thanks
>    Klaus
> 
> > Hi,
> >
> > I have a problem with using the UART1 on a atmega128 simulation. My
> > application that is running fine on hardware seems to cause some
> > troubles in the simulator. The actual program was using the
> > procyon-avrlib for higher-level access to the uart. Using it caused
> > the simulation to stall after transmitting a byte. Changing the
> > baudrate changed it, but would still lead to unwanted behaviour.
> > I have created a small program that sets up the uart and sends bytes
> > with a delay to test for the behaviour. The debug output reveals that
> > it seems to be trapped in the IRQ. After the first byte has been
> > transmitted it would repeat the debug output from the irq handler.
> > Could there be a problem in the simulator with clearing the TXC
> > interrupt after it has been thrown?
> > On the same note, on my receiving end I am using a modified serialrx
> > class to listen to the UART1. Even with the irq problem I am having,
> > the first byte is being transmitted. However, for this to work I have
> > to set up the baudrate in the serialrx class to 2*19200 for it to
> > work.
> > My F_CPU is 16000000
> > I set up the simulation with
> > dev1->SetClockFreq(1000/16);
> >
> > anything I am missing? Help would be greatly appreciated.
> > btw.: Great code! Very easy to read.
> >
> > //----- Include Files
> > ---------------------------------------------------------
> > #include <avr/io.h>
> > #include <avr/signal.h>
> > #include <avr/interrupt.h>
> >
> > #include "global.h"
> >
> > #define UART1_BAUD  19200
> >
> > //----- Begin Code
> > ------------------------------------------------------------
> >
> > volatile u08   uartReadyTx;
> >
> > int main(void)
> > {
> >    // set LED pins for output
> >    DDRA = _BV(DDA2) | _BV(DDA4);
> >
> >    // set BAUD rate for UART1
> >    UBRR1L = ((F_CPU+(UART1_BAUD * 8L))/(UART1_BAUD * 16L)-1);
> >    UBRR1H = 0;
> >
> >    // init UART1 and enable TXC interupt
> >    UCSR1B = BV(TXEN)|BV(TXCIE);
> >
> >    uartReadyTx = 0;
> >
> >    // enable all interupts
> >    sei();
> >
> >    while(1) {
> >       // wait for uart to be ready
> >       while( uartReadyTx );
> >
> >       // delay
> >       int m = 33000;
> >       while( m-- );
> >
> >       // send byte through uart
> >       UDR1 = 0x55;
> >       // set uart not ready
> >       uartReadyTx = 1;
> >
> >       // debug
> >       sbi( PORTA, PA2);
> >       cbi( PORTA, PA2);
> >    }
> >
> >    return 0;
> > }
> >
> > INTERRUPT(SIG_UART1_TRANS)
> > {
> >    // debug
> >    sbi( PORTA, PA4);
> >    cbi( PORTA, PA4);
> >
> >    // set uart ready
> >    uartReadyTx = 0;
> > }
> >
> >
> > _______________________________________________
> > Simulavr-devel mailing list
> > address@hidden
> > http://lists.nongnu.org/mailman/listinfo/simulavr-devel
> >
> 
> --
> +++ Lassen Sie Ihren Gedanken freien Lauf... z.B. per FreeSMS +++
> GMX bietet bis zu 100 FreeSMS/Monat: http://www.gmx.net/de/go/mail
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]