Altera_Forum
Honored Contributor
20 years agouart functionally
hi
if somebody want to try uart device , i post a simple code that's running of course it's not complete but i would like to start a common little project with all people write in this community . # include "count_binary.h" int val; int uart_0; char buf[255]; alt_u8 counter; // REGISTER static void handle_uart_interrupt(void* context,alt_u32 id) { val++; //everytime i receive a caracter increment and display on leds Write_Output(val); //using this macro automatically bit ready to receive will be resetted //and ready for a new interrupt when shifter register finish to translate last bit //in the uart device buf[counter]=IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE) ; counter++; if (counter==6) {printf("riceived:%s\r ",buf); counter=0; } } static void Write_Output(alt_u8 val) { IOWR_ALTERA_AVALON_PIO_DATA(PM_OUT_BASE, val); } int main(void) { int i; volatile int uart_0; val=0; while( 1 ) { IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE, 0x180); alt_irq_register(UART_0_IRQ,&uart_0,handle_uart_interrupt); } return(0); } i use vc#.net to send a string ("walter") of 6 caracters . In Nios II ide console is displaying as follows received:walter i think this sample will be good for many people want to start to use uart device and interrupt . I stay 2 days reading and trying to gain this , i'm not clever . Of course need to implement also transmit interrupt and create a protocol but if other people contribute to continue it's possible to obtain very interesting development ciao walter