Forum Discussion
Altera_Forum
Honored Contributor
15 years agoInterrupt Nios II RS232 / Usart
Hello! I am trying to use the rs232 interrupt. sending and receiving data works fine, but when i try to use the interrupt to receive data I get some problems. this is the rs232 block in my...
Altera_Forum
Honored Contributor
15 years agoI red the other thread and now my isr works, but now the write function does not work..nothing is send, only the RXD comes
volatile int counter; init RXD /* flush any characters sitting in the holding register */ IORD(UART_RS232_BASE, 0); IORD(UART_RS232_BASE, 0); /* reset most of the status register bits */ IOWR(UART_RS232_BASE, 2, 0x00); /* install IRQ service routine */ alt_irq_register(UART_RS232_IRQ, 0, serial_irq_0); /* enable irq for Rx. */ IOWR(UART_RS232_BASE, 3, 0x0080); The ISR is so: static void serial_irq_0(void* context , alt_u32 id) { unsigned int stat,temp; int chr[3]; // message[0]=getc(fp_read); /* get serial status */ stat = IORD(UART_RS232_BASE, 2); /* character Rx */ if (stat & 0x0080) { message [counter]= IORD(UART_RS232_BASE, 0); } if(counter==2){ printf("char: %c%c%c",message[0],message[1],message[2]); counter=0; } else counter++; } In a Task I wrote this to write: FILE *fp_write; fp_write = fopen("/dev/uart_rs232", "w+"); //also used r+ if(fp_write) { //printf("Verbunden\n"); fwrite(pic_viewer->message, strlen(pic_viewer->message), 1, fp_write); OSTimeDlyHMSM(0, 0, 0, (20)); //fwrite(msg,strlen(msg),1,fp); //sprintf(msg,"%i",400); //fwrite(msg, strlen(msg),1,fp); //fprintf(fp, "Closing the UART file.\n"); fclose(fp_write); sprintf(pic_viewer->message,"%s","00050200"); } else { printf("Error/dev/ttyS0\n"); }