avr-gcc-list
[Top][All Lists]
Advanced

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

RE: [avr-gcc-list] basic UART Transmit interrupt problem


From: Darren P
Subject: RE: [avr-gcc-list] basic UART Transmit interrupt problem
Date: Wed, 2 Jul 2003 20:41:47 -0600

Hi,
Your problem is that you have not defined the ISR correctly, "SIGNAL(
SIG_UART_TRANS )" should be "SIGNAL( SIG_UART0_TRANS )", you must specify
which UART the ISR is for (there are 2 UARTs in the Mega128).

The reason the uC would restart is because gcc places "jmp 0x0000" (jump to
the reset vector) at vector locations where no ISR has been defined.

Regards,
Darren

> Hello all,
>
> I run an atmega128L and am currently trying to transmit to the uart using
> the transmit interrupt.  The problem is, when I send a byte after enabling
> the transmit interrupt via
>
>   UCSR0B = (1<<TXEN)|(1<<TXCIE);
>   udr0 = 'A';
>
> the byte gets sent, but then the program restarts from main, without
> triggering my interrupt.  It's weird behavior.  Any help would be greatly
> appreciated.  Here is the code.
>
> #include <avr/interrupt.h>
> #include <avr/io.h>
> #include <avr/signal.h>
>
> static volatile unsigned char *uart_data_ptr;
> static volatile unsigned char uart_counter;
> static volatile unsigned char led;
>
> SIGNAL( SIG_UART_TRANS ) {
>   uart_data_ptr++;
>
>   if(--uart_counter)
>     outp(*uart_data_ptr, UDR0);
> }
>
> void setRedLed(int on) {
>   if(on) {
>     cbi(PORTA, 2);
>   } else {
>     sbi(PORTA, 2);
>   }
> }
>
> void initRedLed(void) {
>   sbi(DDRA, 2);
>   setRedLed(0);
> }
>
> //I am transmitting at 57600
> void init(void) {
>   UBRR0H = 0;
>   UBRR0L = 15;
>
>   UCSR0A = 1<<U2X;
>
>   UCSR0B = (1<<TXEN)|(1<<TXCIE);
>
>   UCSR0C = (1<<UCSZ1)|(1<<UCSZ0);
> }
>
> void uart_send(unsigned char *buf, unsigned char size) {
>   if(!uart_counter) {
>     uart_counter = size;
>     uart_data_ptr = buf;
>     UDR0 = *buf;
>     // CRASHES HERE AND JUMPS BACK TO MAIN,
>     // THE BYTE DOES GET SENT
>     // DOESN'T CRASH IF I DON'T ENABLE TXCIE
>   }
> }
>
> int main(void) {
>   unsigned char i, j, k, l, m;
>
>   initRedLed();
>
>   // Debug to know restarted
>   led = 0;
>   for(m=0; m<10; m++) {
>     setRedLed(!led);
>     led = ~led;
>     for(i=0; i<255; i++)
>       for(j=0; j<255; j++)
>         for(l=0; l<100; l++)
>           k++;
>   }
>
>   init();
>   sei();
>
>   uart_send("HELLO WORLD", 12);
>
>   for(;;) { k++; }
> }
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list




reply via email to

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