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

UART and XBee and NIOS II

Altera_Forum
Honored Contributor II
1,479 Views

Hello,  

 

I need help. 

Based on my intensive internet search, all I need to connect to an Zigbee network using the FPGA (NIOS II) is a UART. 

 

Here are my queries: 

 

(1) Can I use IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE) to recieve the data from the XBee module, 

and in return, using IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, data) to transmit the data? 

 

If yes to (1), what should I be receiving. 

 

I have created an integer array for the receive data: int uart_rx[1024] for each rx request, see code below: 

 

int i = 0; 

 

while(1) { 

if ( IORD_ALTERA_AVALON_UART_STATUS(UART1_BASE) && 0XE0 ) 

uart_rx[i] = IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE); 

i++; 

 

 

The array are filled with a bunch of numbers, my second question is, what I am receving? 

 

Thank you.
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
753 Views

You're nearly there... 

 

Assuming you're right regarding the requirements of your Zigbee interface (I don't KNOW that is what it requires, but believe it is) then 'Yes' to (1) - you can use the commands you've identified to communicate with a UART peripheral connected to a Nios processor. 

 

However, I think you're code isn't quite what you want. 

 

You've correctly identified that you need to test the UART's 'STATUS' register. I assume you're intending to test whether there is a new receive character in the receive buffer. However, for that your bit mask and AND operator are incorrect. 

 

When a new character is available in the 'RXDATA' register, the 'rrdy' bit is set in the 'STATUS' register. That is bit 7 of the 'STATUS'. 

 

So you need to test 

if(IORD_ALTERA_AVALON_UART_STATUS(UART1_BASE) & 0X80) 

to establish whether there is a valid character in the receive buffer. 

 

Your current test is testing the status of 3 bits of the 'STATUS' register - transmit empty, transmit ready & receive char ready. I'm not sure why you would want to test those three bits at the same time.
0 Kudos
Reply