我试图从终端发送AT命令认为USART1,然后使用USART2到GSM调制解调器[终端 - > USART1 - > USART2 - >调制解调器]。发送AT命令后,调制解调器不会发回任何东西。可能是什么问题? USART1工作正常。我正在使用STM32 Nucleo和Keil uVision4。
发送功能
void send_usart2(char *msg){
send_usart1("USART2 sending..."); send_usart1("\r\n");
while (*msg){
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, *msg++);
}
send_usart1("USART2 sending successful"); send_usart1("\r\n");
}
USART2处理程序
void USART2_IRQHandler(void){
int index = 0;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET){
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
Received_values[index++] = USART_ReceiveData(USART2);
}
}
中断初始化
void InitInterrupt2(void) {
NVIC_InitTypeDef NVIC_InitStruct2;
NVIC_InitStruct2.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStruct2.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct2.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct2.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct2);
}
UART初始化
void InitUART2(void) {
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
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(USART2,&USART_InitStructure); /* Configure USAR1 */
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2,ENABLE); /* Enable the USART1 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
这看起来就像我发送的那样。
.....
send_usart2(Command_buffer);
send_usart1("Command: ");
send_usart1(Command_buffer);
send_usart1("\r\n");
memset(Command_buffer, NULL, sizeof(Command_buffer));
os_dly_wait(500);
send_usart1("Received values: ");
send_usart1(Received_values);
send_usart1("\r\n");
memset(Received_values, NULL, sizeof(Received_values));
.......
答案 0 :(得分:0)
我需要配置此行格式:
USART_HardwareFlowControl = USART_HardwareFlowControl_None;
要:
USART_HardwareFlowControl = USART_HardwareFlowControl_RTS;
这意味着USART2和调制解调器需要“握手”连接类型。