Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12746 Discussions

get data from GPS through UART port

Altera_Forum
Honored Contributor II
1,610 Views

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!
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
881 Views

 

--- Quote Start ---  

originally posted by termi@May 9 2006, 02:01 PM 

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. 

... 

... 

... 

thank you! 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=15239) 

--- quote end ---  

 

--- Quote End ---  

 

 

In short, yes, you do need to match the baud rate, data/stop bits, etc. exactly between GPS and Nios UART. You can do this in a couple of ways -- if you do not need to reconfigure the UART in operation (via software) I&#39;d recomend opening the Quartus project associated with your hardware design, launching SOPC Builder, and then editing the properties of the UART you&#39;re using.. you can change these settings, re-generate, re-compile, and then the UART should always operate at 4800 baud. 

 

On a side note, this sounds interesting! I&#39;ve been wanting to do a project like this for some time but as usual, more important things get in the way of it...
0 Kudos
Altera_Forum
Honored Contributor II
881 Views

Thank you, Jesse! 

I tried to change the settings of UART in hardware. 

As I always work on software, I didn&#39;t know much about hardware. 

 

What I did is that, I opened the example hardware design "full-featured" in Quartus, launched SoPC builder, changed the baud rate of UART, and then generated it. 

 

But the error occured showed in the following: 

 

 

ERROR: 

 

The argument "--system_directory=F:/altera/kits/nios2/examples/vhdl/niosII_stratix_1s10/full_featured" contains a space. So sorry. 

 

Error in processing. System NOT successfully generated.  

 

 

What&#39;s wrong?
0 Kudos
Altera_Forum
Honored Contributor II
881 Views

I already solved the problem above, but My FPGA can&#39;t get data from GPS yet. 

Now the baud rate is same. It&#39;s strange that I just can get some commas, which is included in the GPS data sentences, but no other useful data. 

 

Maybe there are some problems in my codes. Or something else I didn&#39;t find. 

Also I don&#39;t know much about serial communication. 

Hope for help if there are some ideas in your mind.
0 Kudos
Reply