[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Simulavr-devel] UART Interrupt and Timer problem
From: |
Jakob Schwendner |
Subject: |
[Simulavr-devel] UART Interrupt and Timer problem |
Date: |
Tue, 10 May 2005 10:24:45 +1000 |
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] UART Interrupt and Timer problem,
Jakob Schwendner <=