stm32f103c8t6通过串口发送at指令代码
时间: 2024-06-01 07:06:25 浏览: 57
stm32f103c8t6 can send代码
以下是通过串口发送AT指令的示例代码,你可以根据自己的实际情况进行修改。
```c
#include "stm32f10x.h"
USART_InitTypeDef USART_InitStructure;
void USART_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}
void USART_Send_AT_Command(char* command)
{
while(*command)
{
USART_SendData(USART1, *command++);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
}
}
int main(void)
{
USART_Configuration();
char* command = "AT\r\n";
USART_Send_AT_Command(command);
while(1);
return 0;
}
```
阅读全文