接收 AT 命令

Receiving AT commands

我正在使用微控制器与 SIM808 模块通信,我想发送和接收 AT 命令。

现在的问题是有些命令我只收到了一部分我应该收到的答案,但有些命令我收到了我应该收到的答案。例如,如果我按预期关闭收到 "NORMAL POWER DOWN" 的模块。

我相信我收到了一切,只是我无法看到它。我收到了响应的开头和结尾,所以问题应该在我解析和缓冲的方式上。我正在使用 FIFO 缓冲 RXC 中断。

例如,对于命令 "AT+CBC",我应该收到如下信息:

” +中国银行:1,96,4175 好的 “

但我收到“+CBC1,4130OK”

(我把看不懂的字符换成了点)

bool USART_RXBufferData_Available(USART_data_t * usart_data)
{
    /* Make copies to make sure that volatile access is specified. */
    uint8_t tempHead = usart_data->buffer.RX_Head;
    uint8_t tempTail = usart_data->buffer.RX_Tail;

    /* There are data left in the buffer unless Head and Tail are equal. */
    return (tempHead != tempTail);
}


uint8_t USART_receive_array (USART_data_t * usart_data, uint8_t * arraybuffer)
{
    uint8_t i = 0;
    while (USART_RXBufferData_Available(usart_data))
    {
        arraybuffer[i] = USART_RXBuffer_GetByte(usart_data);
        ++i;
    }

    return i;
}


void USART_send_array (USART_data_t * usart_data, uint8_t * arraybuffer, uint8_t buffersize)
{
    uint8_t i = 0;

    /* Wait until it is possible to put data into TX data register.
    * NOTE: If TXDataRegister never becomes empty this will be a DEADLOCK. */
    while (i < buffersize)
    {
        bool byteToBuffer;
        byteToBuffer = USART_TXBuffer_PutByte(usart_data, arraybuffer[i]);
        if(byteToBuffer)
        {
            ++i;
        }
    }
}

void send_AT(char * command){

    uint8_t TXbuff_size = strlen((const char*)command);

    USART_send_array(&expa_USART_data, (uint8_t *)command, TXbuff_size);

    fprintf(PRINT_DEBUG, "Sent: %s\n\n", command);

}

void receive_AT(uint8_t *RXbuff){

    memset (RXbuff, 0, 100);

    uint8_t bytes = 0;

    bytes = USART_receive_array(&expa_USART_data, RXbuff);

    int n;
    if (bytes>0)
    {
        RXbuff[bytes]=0;
        for (n=0;n<bytes;n++)
        {
            if (RXbuff[n]<32)
            {
                RXbuff[n]='.';
            }
        }
     }

     fprintf(PRINT_DEBUG, "Received: %s\n\n", RXbuff);

    }

int main(){

unsigned char RXbuff[2000];

send_AT("ATE0\r\n");
receive_AT(RXbuff);

send_AT("AT\r\n");
receive_AT(RXbuff);

send_AT("AT+IPR=9600\r\n");
receive_AT(RXbuff);

send_AT("AT+ECHARGE=1\r\n");
receive_AT(RXbuff);

send_AT("AT+CBC\r\n");
_delay_ms(2000);
receive_AT(RXbuff);

send_AT("AT+CSQ\r\n");
_delay_ms(2000);
receive_AT(RXbuff);

}

因此,问题与这部分代码无关。我正在使用模拟串行端口将内容从微控制器打印到 PC。问题是我向 PC 打印字符的速度比 PC 接收的速度快得多,这就是为什么有些部分没有出现的原因。