Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20704 Discussions

Problem with UART using register

Altera_Forum
Honored Contributor II
1,480 Views

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);
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
648 Views

hi, same mistake 

 

try with ALTERA_AVALON_UART_STATUS_tRDY_MSK. 

 

I don't know why it works for me. 

 

EDIT : Sorry, wrong way
0 Kudos
Altera_Forum
Honored Contributor II
648 Views

Here I don't send data, so the bit TRDY is always at 1. 

Else, this phenomenon is strange because, if I enable interrupt on reception, when I have an interrupt I get all bytes correctly using the same method.
0 Kudos
Altera_Forum
Honored Contributor II
648 Views

I use this in "interrupt on reception", it works well. 

 

In a superloop, reading if RRDY is active is not recommended I think. 

It is a mistake for me too.
0 Kudos
Reply