Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Uart loopback

Altera_Forum
Honored Contributor II
2,094 Views

Hello guys, 

 

I have created a nios2 system with a uart port: uart_0 

 

I have put the rx_uart and tx_uart in short circuit. So I expect that what I send is what I get. 

 

Finally I have writtend this code: 

 

#include <stdio.h># include <unistd.h># include <stdint.h># include <fcntl.h># include "sys/alt_stdio.h"# include "system.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_uart.h" int main() { uint8_t tx_var=0xFF; uint8_t rrdy=0x00; uint8_t trdy=0x00; uint8_t tmt=0x00; uint16_t status=0x00; uint8_t rx_var=0x00; //write the byte to be sent printf("Scrivo il byte da trasmettere.\n"); IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE, tx_var); status=IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); tmt=(status & ALTERA_AVALON_UART_STATUS_TMT_MSK)>>5; while(tmt != 1){ //Untill the byte is not trasmitted status=IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); tmt=(status & ALTERA_AVALON_UART_STATUS_TMT_MSK)>>5; } rrdy=(status & ALTERA_AVALON_UART_STATUS_RRDY_MSK ) >> ALTERA_AVALON_UART_STATUS_RRDY_OFST; while(rrdy !=1){//until the byte is not received rrdy=(status & ALTERA_AVALON_UART_STATUS_RRDY_MSK ) >> ALTERA_AVALON_UART_STATUS_RRDY_OFST; printf("status RRDY bit= %x\n", rrdy); }; rx_var = IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE); printf("rx_data= %x\n\n", rx_var); return 0; } 

 

The problem is that nothing is received. After i have executed the iowr_altera_avalon_uart_txdata(uart_0_base, tx_var); i can see the tmt bit of the status register change from 0 to 1 and from 1 to 0. So that it seems that the process of transmitting is going well. By the way I have noticed that the tx_uart pin i s always at 0 V. May be a bad pin assignment or I have to do something else to have the byte transmitted ? 

 

I hope to have been sufficiently clear. 

 

Have a nice day.
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
1,227 Views

I think a good place to start is to first make sure you can transmit a character and see it on an oscilloscope. Start out by bringing this pin to an output line and looking at it with an oscilloscope. You could also do this with Signaltap, but you may need to create a very deep memory b/c the serial transmission will likely be long relative to the clock frequency. My memory is that the UART tx line should be resting at a '1' normally, then toggling low during character times. 

 

Good luck! 

 

 

 

 

--- Quote Start ---  

Hello guys, 

 

I have created a nios2 system with a uart port: uart_0 

 

I have put the rx_uart and tx_uart in short circuit. So I expect that what I send is what I get. 

 

Finally I have writtend this code: 

 

#include <stdio.h># include <unistd.h># include <stdint.h># include <fcntl.h># include "sys/alt_stdio.h"# include "system.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_uart.h" int main() { uint8_t tx_var=0xFF; uint8_t rrdy=0x00; uint8_t trdy=0x00; uint8_t tmt=0x00; uint16_t status=0x00; uint8_t rx_var=0x00; //write the byte to be sent printf("Scrivo il byte da trasmettere.\n"); IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE, tx_var); status=IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); tmt=(status & ALTERA_AVALON_UART_STATUS_TMT_MSK)>>5; while(tmt != 1){ //Untill the byte is not trasmitted status=IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); tmt=(status & ALTERA_AVALON_UART_STATUS_TMT_MSK)>>5; } rrdy=(status & ALTERA_AVALON_UART_STATUS_RRDY_MSK ) >> ALTERA_AVALON_UART_STATUS_RRDY_OFST; while(rrdy !=1){//until the byte is not received rrdy=(status & ALTERA_AVALON_UART_STATUS_RRDY_MSK ) >> ALTERA_AVALON_UART_STATUS_RRDY_OFST; printf("status RRDY bit= %x\n", rrdy); }; rx_var = IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE); printf("rx_data= %x\n\n", rx_var); return 0; } 

 

The problem is that nothing is received. After i have executed the iowr_altera_avalon_uart_txdata(uart_0_base, tx_var); i can see the tmt bit of the status register change from 0 to 1 and from 1 to 0. So that it seems that the process of transmitting is going well. By the way I have noticed that the tx_uart pin i s always at 0 V. May be a bad pin assignment or I have to do something else to have the byte transmitted ? 

 

I hope to have been sufficiently clear. 

 

Have a nice day. 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
1,227 Views

Thank you for your reply !! I have tried with a multimeter and I put the write comman in a loop. What I see is that the pin is always at 0 V. 

 

There is an instruction that put a specified pin (eg pin_d22) on high state so that i can test if the pin i have assigned to the txd_uart is the pin I really use in hardware ? It could be harmful ? 

 

Alternatively what about if I set the output pin (tx_uart) as the clock pin ?  

 

Thank you !! 

 

Have a nice day.
0 Kudos
Altera_Forum
Honored Contributor II
1,227 Views

 

--- Quote Start ---  

Thank you for your reply !! I have tried with a multimeter and I put the write comman in a loop. What I see is that the pin is always at 0 V. 

 

There is an instruction that put a specified pin (eg pin_d22) on high state so that i can test if the pin i have assigned to the txd_uart is the pin I really use in hardware ? It could be harmful ? 

 

Alternatively what about if I set the output pin (tx_uart) as the clock pin ?  

 

Thank you !! 

 

Have a nice day. 

--- Quote End ---  

 

 

I have put the input clock on the output pin assigned to the txd_uart but still cannot see anything.. mumble mumble.. 

 

any suggestion ??
0 Kudos
Altera_Forum
Honored Contributor II
1,227 Views

A few possibilities: 

  1. If you are using an RS232 converter, it probably can't operate above a few hundred KHz. Make sure you're looking at the input to the RS232 converter. 

  2. Go into the assignment tool and verify that the txd_uart signal (or the clock signal) is routed to the correct FPGA pin. 

  3. Possibly check other pin assignments as well. 

  4. Check to make sure you have a clock! 

  5. Search and make sure that the txd_uart signal isn't routed to multiple places (some languages allow this). 

  6. Check to see if the FPGA really loaded? 

0 Kudos
Altera_Forum
Honored Contributor II
1,227 Views

SOLVED ! 

 

There were two main problems.. 

 

1- On the fpga gived to me were missing two IC that were driving the signals on the pins I was measuring 

2- I was using a higher clock.. I needed a PLL divisor on my quartus design to see the clock out of the txd_pin. 

 

Now all the systems are up and running. Thank you !!! 

 

have a nice day
0 Kudos
Reply