Altera_Forum
Honored Contributor
13 years agoUART Interrupt Mode
I'm trying to use a Nios II system to send and receive messages over RS232 UART. My applications requires a non-blocking read operation, so I am trying to configure the UART to work in interrupt mode so I don't lose any characters. All I need to do is have an ISR that buffers received characters, so when I call the read method, I can read characters from that buffer or immediately return 0 if the buffer is empty. I know that the HAL drivers provide an interrupt handler for the UART and I think this will be sufficient for my purposes.
I am having problems getting the UART to work in interrupt mode and I haven't been able to find any good example software for Nios II interrupt mode using the provide HAL ISR. 1. Does my code need to explicitly enable interrupts? Should this be done before or after opening the UART in nonblocking mode with fd = open(uart_path, O_RDWR | O_NONBLOCK | O_NOCTTY);? 2. How can I read from the circular buffer used by the HAL ISR? In polling mode, I use read(fd, data_byte, 1), will this also work in interrupt mode? 3. Does interrupt mode affect writing to the UART? Can I still use the write(fd, &data_byte, 1) function for writes? My basic code structure iswhile (1) {while (no data to read) {//do work
}
//process read message
//send response message
}