Gps AVR USART不';I don’我没有按预期工作

Gps AVR USART不';I don’我没有按预期工作,gps,avr,uart,atmega,Gps,Avr,Uart,Atmega,我使用带有GPS模块的ATMega32在LCD显示屏上显示一些数据(经度和纬度)。 GPS模块每秒以9600 bps的速度发送一串数据。 该字符串是一个NMEA语句,以$符号开头,我使用该字符同步接收器(AVR UART) 这是我使用的代码: // GPS.h void GPS_read(char *sentence) { while ((*sentence = USART_receive()) != '$') ; USART_receive_string

我使用带有GPS模块的ATMega32在LCD显示屏上显示一些数据(经度和纬度)。 GPS模块每秒以9600 bps的速度发送一串数据。 该字符串是一个NMEA语句,以$符号开头,我使用该字符同步接收器(AVR UART)

这是我使用的代码:

// GPS.h

void GPS_read(char *sentence)           
{
  while ((*sentence = USART_receive()) != '$')
    ;
  USART_receive_string(++sentence);
}



// USART.h

unsigned char USART_receive(void)
{
  while (!(UCSRA & (1<<RXC)))
    ;
  return UDR;
}

void USART_receive_string(char *string)
{
  do
  {
    *string = USART_receive();
  } while (*string++ != '\n');                             // NMEA sentences are <CR><LF> terminated
  *string = '\0';   
}
//GPS.h
无效GPS_读取(字符*句子)
{
而((*句子=USART_receive())!='$')
;
USART_接收_字符串(++句子);
}
//乌萨特·h
未签名字符USART\U接收(无效)
{

当(!(UCSRA&(1)检查TX和RX的波特率是否正确时,请检查帧错误。

您的代码有一些错误,请尝试以下操作:

您还没有包含char数组声明,但我建议您使用索引器跟踪数组中正在读取和/或写入的元素

unsigned char Sentence[*Insert array size here*];
unsigned char Indexer = 0;
至于你的函数,我想说你的USART_receive()函数很好,但是试试

void GPS_read(char *sentence)
{
    unsigned char Data = USART_receive();   // Read initial value
    while (Data != '$')                     // while Data is not a '$' ...
        Data = USART_receive();             // ... Read the USART again until it is

    sentence[Indexer++] = Data;
    USART_receive_string(sentence);        
}

void USART_receive_string(char *string)
{
    unsigned char Data = USART_receive();

    while (Data != '\n')
    {
        *string[Indexer++] = Data;
        Data = USART_receive();
    }
    *string[Indexer] = '\n';
}

*句子[Indexer++]
?-我不这么认为。“您的代码有一些错误”-这些错误是什么?为什么?*句子指向字符数组的地址,索引被用作索引器,一旦数据值存储到数组的特定元素,将索引器增加一个,以“指向”数组中的下一个元素,以便使用art\u receive\u string()功能。我缺少什么?不,
句子
指向某个东西,
*句子
是一个
字符
。啊,看不到我脸上的表情-我已经编辑了答案。