Altera_Forum
Honored Contributor
16 years agoRS232 Qestion in Cyclone III evaluation board.
Hi,
I am working on a simple example to test the functionality of RS232. I wrote a code based on the example online. However, when the program enter interrupt for the first time. It will hang there and wait for data forever. If I just remove that line, it will repeatedly print out "Test" forever. In the hardware part, I set the RXD to PIN_E18 and TXD to PIN_H17. Did I ignore other setting in this part? Please help me to figure out this problem comes from software or hardware. Thank you so much. cyclone iii evaluation board.nios ii embedded evaluation kit output Hello World UART Testing Debug 1 Debug 2 Debug 3 Check pin assignment set_location_assignment PIN_E18 -to rxd_to_the_uart_0 set_location_assignment PIN_H17 -to txd_from_the_uart_0 sample code# include "alt_types.h"# include "sys/alt_stdio.h"# include "system.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_pio_regs.h"# include "sys/alt_irq.h" void uart_handle(void *context,alt_u32 interrupt) { alt_putstr("Check"); unsigned short int data,status; status = IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); while (!(status & ALTERA_AVALON_UART_STATUS_RRDY_MSK)) status = IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); data =IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE); //write status reg; status = ALTERA_AVALON_UART_STATUS_TRDY_MSK; IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, status); IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE, data); IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0); alt_putstr("Test"); } void uart_init() { alt_u32 control; volatile unsigned long uart_capture; int divisor; alt_putstr("Debug 1\n"); control = ALTERA_AVALON_UART_CONTROL_TRDY_MSK | ALTERA_AVALON_UART_CONTROL_RRDY_MSK | ALTERA_AVALON_UART_CONTROL_E_MSK; IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE, control); alt_putstr("Debug 2\n"); divisor = (int)(50000000/9600+0.5); IOWR_ALTERA_AVALON_UART_DIVISOR(UART_0_BASE, divisor); alt_putstr("Debug 3\n"); if (alt_irq_register(UART_0_IRQ, (void*)uart_capture, uart_handle)) { //IOWR_ALTERA_AVALON_PIO_DATA(PIO_OUT_BASE, 0x0); alt_putstr("Debug 4\n"); IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, 0x03); } else{ alt_putstr("Debug 5\n"); IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, 0x0a); } alt_putstr("Debug 6\n"); } int main(void) { /* declare var used by uart;*/ //IOWR_ALTERA_AVALON_PIO_DATA(PIO_OUT_BASE, 0x4079); alt_putstr("Hello World\n"); alt_putstr("UART Testing\n"); uart_init(); alt_putstr("Initialized\n"); while(1); return 0; }