Altera_Forum
Honored Contributor
12 years agoUart loopback
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.