From: "Rego, P." <pvrego@gmail.com>
Subject: Interrupt-driven Usart not working in Ada, but in C working, why?
Date: Sun, 16 Mar 2014 13:37:45 -0700 (PDT)
Date: 2014-03-16T13:37:45-07:00 [thread overview]
Message-ID: <2528b8c4-93a8-4fb8-a6a5-192493d5d616@googlegroups.com> (raw)
I am trying to use interrupt-driven Usart on an Atmel AVR ATmega2560 chip.
The problem is that when I send anything to the usart, the Ada application restarts (continuously). I simplified the codes and created a C version (or the nearer of it) of the same code (because at first I thought that it could be a hw problem or a datasheet misunderstanding of me, and AVR community would not answer me if I had posted Ada code instead of C code ...). But the C code worked (i.e., the usart echo appears, and the board is not restarted), ao now I became clueless. Maybe the AVR guys could help me? Thanks.
The simplified version of the codes are
-- main.adb
with System.Machine_Code;
with AVR.USART;
with TEST;
pragma Unreferenced (TEST);
procedure Main is
F_CPU : constant := 16_000_000;
USART_BAUDRATE : constant := 9600;
begin
AVR.USART.Reg_USART1.UCSRB.RXEN := True;
AVR.USART.Reg_USART1.UCSRB.TXEN := True;
AVR.USART.Reg_USART1.UCSRB.RXCIE := True;
AVR.USART.Reg_USART1.UCSRC.UCSZ0 := True;
AVR.USART.Reg_USART1.UCSRC.UCSZ1 := True;
AVR.USART.Reg_USART1.UBRR (0) := AVR.Byte_Type ((F_CPU / (USART_BAUDRATE * 16)) - 1);
AVR.USART.Reg_USART1.UBRR (1) := 0;
System.Machine_Code.Asm ("sei", Volatile => True);
loop
null;
end loop;
end Main;
-- test.ads
package TEST is
USART1RX : constant String := "__vector_36";
procedure Handle_Interrupt_USART1_RX;
pragma Machine_Attribute
(Entity => Handle_Interrupt_USART1_RX,
Attribute_Name => "signal");
pragma Export
(Convention => C,
Entity => Handle_Interrupt_USART1_RX,
External_Name => USART1RX);
end TEST;
with AVR;
with AVR.USART;
-- test.adb
package body Test is
procedure Handle_Interrupt_USART1_RX is
Curr_Buffer : AVR.Byte_Type;
begin
Curr_Buffer := AVR.USART.Reg_USART1.UDR;
AVR.USART.Reg_USART1.UDR := Curr_Buffer;
end Handle_Interrupt_USART1_RX;
end Test;
Given that I have mapped the Usart registers correctly on AVR.USART package (because my JtagICE said so).
The C code is
-- simple_isr_usart.c
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 16000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
int main (void){
UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
UBRR0H = (BAUD_PRESCALE >> 8);
UBRR0L = BAUD_PRESCALE;
sei();
while (1) {}
}
ISR(USART0_RX_vect){
char ReceivedByte;
ReceivedByte = UDR0;
UDR0 = ReceivedByte;
}
next reply other threads:[~2014-03-16 20:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-16 20:37 Rego, P. [this message]
2014-03-16 22:54 ` Interrupt-driven Usart not working in Ada, but in C working, why? Oliver Kleinke
2014-03-17 0:21 ` Rego, P.
2014-03-17 14:08 ` Oliver Kleinke
2014-03-24 14:36 ` rrr.eee.27
2014-03-16 23:09 ` Oliver Kleinke
2014-03-17 0:32 ` Rego, P.
2014-03-17 12:17 ` rrr.eee.27
2014-03-17 20:28 ` Rego, P.
2014-03-18 14:08 ` Oliver Kleinke
2014-03-21 2:52 ` Rego, P.
2014-03-24 14:28 ` rrr.eee.27
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox