Altera_Forum
Honored Contributor
19 years agoand another uart problem.
hello guys,
i'm having a problem with my FIFOED UART, The only thing im trying to do i send a big file over the uart and show on the Nios 2 Console that the data actually is being received. the problem is that when i send a few characters with a terminal program. i do see the characters on the NIOS2 console but my variabele Fifo_index isn't increased. and when i try to send a lot of character, lets say 200+, my program freezes immediately. can someon help me with this? btw im using the FIFOED AVALON UART from this forum running on 9600 baud (for starters) with a Fifo of 512 words. to make this a little easier, the code:#include <stdio.h># include <string.h># include <system.h># include <sys/alt_irq.h># include <altera_avalon_pio_regs.h># include <fifoed_avalon_uart_regs.h>
/*--------------------------------Definitions----------------------------------*/
/*---------------------------Only Capital letters-----------------------------*/
/*----------------------------------------------------------------------------*/
# define BAUDRATE 9600# define UART_RX_RINGBUFFER_SIZE 2048# define UART_TX_RINGBUFFER_SIZE 2048
/*--------------------------------Prototypes----------------------------------*/
void Uart_Init();
void FIFOED_AVALON_UART_0_ISR( void* context, alt_u32 id);
/*--------------------------------Variabeles----------------------------------*/
unsigned int UART_Context, i, sleep;
unsigned char Data, test, Heartbeat;
/*----------------------------------------------------------------------------*/
/*------------------------------Main program--------------------------------*/
/*----------------------------------------------------------------------------*/
int main(){
Uart_Init();
printf( "Uart Initilisation \n\r");
for(;;){
// this is just a simple binary counter that counts to 255 and then starts with 0 again
// i did it so that i could see when my program freezes.
sleep = 100000;
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, Heartbeat);
Heartbeat++;
usleep(sleep);
}
}
/*----------------------------------------------------------------------------*/
/*--------------------------------Methods------------------------------------*/
/*----------------------------------------------------------------------------*/
void Uart_Init(){
unsigned int Divisor;
// calculate the divisor for the uart
Divisor = (ALT_CPU_FREQ/BAUDRATE) + 0.5;
// disable all the FIFOED uarts interrupts
IOWR_FIFOED_AVALON_UART_CONTROL(FIFOED_AVALON_UART_0_BASE, 0);
// set baudrate
IOWR_FIFOED_AVALON_UART_DIVISOR(FIFOED_AVALON_UART_0_BASE, Divisor);
// Registrate ISR
alt_irq_register(FIFOED_AVALON_UART_0_IRQ ,(void*) &UART_Context, FIFOED_AVALON_UART_0_ISR);
// enable the RX interrupt
IOWR_FIFOED_AVALON_UART_CONTROL(FIFOED_AVALON_UART_0_BASE, FIFOED_AVALON_UART_CONTROL_RRDY_MSK );
}
/*---------------------------------------------------------------------------*/
/*---------------------Interrupt Service Routines (ISR)----------------------*/
/*---------------------------------------------------------------------------*/
void FIFOED_AVALON_UART_0_ISR(void* context, alt_u32 id){
unsigned char DataCharacter;
unsigned int Status, Control, TempStatus, Fifo_index;
// read both the status and control-register
Status = IORD_FIFOED_AVALON_UART_STATUS(FIFOED_AVALON_UART_0_BASE);
Control = IORD_FIFOED_AVALON_UART_CONTROL(FIFOED_AVALON_UART_0_BASE);
// Clear alle error Flags en Clear de Interrupts
IOWR_FIFOED_AVALON_UART_STATUS(FIFOED_AVALON_UART_0_BASE, 0);
/*----------------------------------------------------------------------------*/
/* ------------------------Uart_Receive_ISR-----------------------------------*/
/*----------------------------------------------------------------------------*/
// when the receive ready interrupts occurs store received data in DataCharacter
if ((Status & FIFOED_AVALON_UART_STATUS_RRDY_MSK) == FIFOED_AVALON_UART_STATUS_RRDY_MSK){
DataCharacter = IORD_FIFOED_AVALON_UART_RXDATA(FIFOED_AVALON_UART_0_BASE);
printf("received data from UART: %d, %c \n" , DataCharacter, DataCharacter);
Fifo_index = IORD_FIFOED_AVALON_UART_RX_FIFO_USED(FIFOED_AVALON_UART_0_BASE);
printf("Fifo_index: %d\n", Fifo_index);
if (Status & FIFOED_AVALON_UART_STATUS_FE_MSK){
printf("framing error\n");
}else if (Status & FIFOED_AVALON_UART_STATUS_PE_MSK ){
printf("Parity error\n");
}else if(Status & FIFOED_AVALON_UART_STATUS_ROE_MSK ){
printf("Receive overrun error\n");
}else {
printf("no errors occured\n");
}
} and a little picture off the nios console picture nios 2 console (http://img174.imageshack.us/my.php?image=problemnm9.png) why isn't my Fifo_index increasing after that text, Fifo_index should equal 6 after that transmission???? Hope someone can help me with this note that im just a new at this programming. and i know its better to use the hal API instead of Directly accesing the registers. but before this i was more into AVR and Microchips.. so thats an old habit