Altera_Forum
Honored Contributor
19 years agoget data from GPS through UART port
Hello everybody,
I'm doing a design, the purpose is to receive data from GPS to FPGA. I use the serial port UART. I have some problem now. The data from GPS is just ASCII text, like the following: $GPGGA,110040,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 But do not care about this. I wrote an interrupt for UART RXD, when there is data coming from GPS, the interrupt happened, read data and put it into a buffer. I should process the data I got, but now the code is just about print the data. However, I got nothing or a lot of squares on the console window. What's wrong with my code? or something else? Moreover, the baud rate of GPS is 4800, then that of UART in my FPGA system is 115200. Do I need to change the rate? And I don't understand the baud rate of UART, could someone give some ideas? the code is following: # define quelen 2048 char queue[quelen]; int input_index = 0; int output_index = 0; static void init_uart_receiver(); static void handle_uart_interrups(void* context, alt_u32 id); int main(void) { int ch; int temp_index; char *gga ="GPGGA"; init_uart_receiver(); while(1) { if(output_index != input_index) { temp_index =output_index; if(temp_index >=quelen) temp_index=0; ch =queue[temp_index]; output_index =temp_index+1; } if(ch=='$') { if(strncmp(gga,&queue[temp_index+1],5)==0) printf("%c", queue[temp_index+7]); } } return 0; } static void init_uart_receiver() { void* status_ptr; IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, 0x80); IOWR_ALTERA_AVALON_UART_STATUS(UART1_BASE, 0x0); IOWR_ALTERA_AVALON_UART_RXDATA(UART1_BASE, 0x0); alt_irq_register(UART1_IRQ,status_ptr,handle_uart_interrups); } static void handle_uart_interrups(void* context, alt_u32 id) { char ch; int temp_index; volatile char* status_ptr =(volatile char*)context; *status_ptr =IORD_ALTERA_AVALON_UART_STATUS(UART1_BASE); if(IORD_ALTERA_AVALON_UART_STATUS(UART1_BASE) ==0x80) { ch =IORD_ALTERA_AVALON_UART_RXDATA(UART1_BASE); temp_index =input_index; if(temp_index>=quelen) temp_index =0; if(temp_index != output_index) { queue[temp_index] =ch; input_index =temp_index+1; } } IOWR_ALTERA_AVALON_UART_STATUS(UART1_BASE, 0x0); } Thank you!