Mam pewien problem z prostym programem, odbierającym dane przez USART.
Chodzi o to, że program się resetuje po powrocie z obsługi przerwania. To znaczy takie mam wrażenie, gdyż wykonuje cały czas instrukcje z przed głównej pętli. Testuję to na AVR Dragon i płycie testowej ZL11AVR.
Wysyłanie danych z procesora działa, obieram na kompie to co chcę. Ale widzę, że się zapętla nie tu gdzie trzeba.
Coś tu robię źle i może ktoś z Was to zauważy
Kod: Zaznacz cały
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "USART.h"
char txt_0[] = "----------";
char txt_1[] = "\r\n";
char txt_2[] = "Podaj komendę";
char txt_3[] = "Odebrano komendę";
char komenda = 0;
int jest_komenda = 0;
SIGNAL(USART_RX_vect)
{
komenda = UDR;
jest_komenda = 1;
asm("nop");
reti();
}
int main(void)
{
USART_Init(12);
USART_TransmitString(txt_0);
USART_TransmitString(txt_0);
USART_TransmitString(txt_1);
USART_TransmitString(txt_2);
USART_TransmitString(txt_1);
USART_TransmitString(txt_0);
USART_TransmitString(txt_0);
sei();
while(1)
{
if(jest_komenda==1)
{
cli();
jest_komenda = 0;
USART_TransmitString(txt_1);
USART_TransmitString(txt_3);
USART_TransmitString(txt_1);
USART_TransmitString("[");
USART_TransmitString(komenda);
USART_TransmitString("]");
USART_TransmitString(txt_0);
USART_TransmitString(txt_0);
sei();
}
}
}