gpt4 book ai didi

c - 接收 AT 命令

转载 作者:太空宇宙 更新时间:2023-11-04 04:28:19 28 4
gpt4 key购买 nike

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

现在的问题是,对于某些命令,我​​只收到了我应该收到的答案的一部分,但对于其他一些命令,我​​收到了我应该收到的答案。例如,如果我关闭模块,我会按预期收到“正常断电”。

我相信我正在接收一切,只是我无法看到它。我收到了响应的开头和结尾,所以问题应该在我解析和缓冲的方式上。我正在使用 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);

}

最佳答案

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

关于c - 接收 AT 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39085047/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com