Altera_Forum
Honored Contributor
16 years agoProblem with UART using register
Hello,
I made a project with a Nios II processor, and I am currently trying to get data from UART. I tried using the getc function and it works fine, I received all the data. I also tried using register (checking the bit RRDY of the status register) but I don't get all the data (in average, I received a third of the data I send, but it is not constant). For the test, I use a simple rs232 terminal (Termite), and send byte by byte manually, so it is not a problem of speed. In my code, I just get data from uart and display the value on leds, I think my code is correct (I put the two methods used below), but I don't see why it doesnot work correctly, if anyone has an idea. Thanks in advance. Jérôme
// Reading uart using HAL (works all the time)
FILE* file;
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, ~0x00);
file = fopen (UART_NAME, "r+");
do
{
data = getc(file);
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, ~data);
}while(1);
// Reading uart using register (works sometimes)
do
{
status = IORD_ALTERA_AVALON_UART_STATUS(UART_BASE);
if( (status & ALTERA_AVALON_UART_STATUS_RRDY_MSK) != 0)
{
data = IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE);
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, ~data);
}
}while(1);