[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] basic UART Transmit interrupt problem
From: |
Woodward, Mark P |
Subject: |
[avr-gcc-list] basic UART Transmit interrupt problem |
Date: |
Wed, 02 Jul 2003 19:00:36 -0700 |
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] basic UART Transmit interrupt problem,
Woodward, Mark P <=
- RE: [avr-gcc-list] basic UART Transmit interrupt problem, Woodward, Mark P, 2003/07/03
- RE: [avr-gcc-list] basic UART Transmit interrupt problem, Woodward, Mark P, 2003/07/03
- RE: [avr-gcc-list] basic UART Transmit interrupt problem, Woodward, Mark P, 2003/07/03
- RE: [avr-gcc-list] basic UART Transmit interrupt problem, Woodward, Mark P, 2003/07/03
- RE: [avr-gcc-list] basic UART Transmit interrupt problem, Woodward, Mark P, 2003/07/03