我串口配置代码如下:
[mw_shl_code=c,true]
USART_InitStructure.Instance = USART1;
USART_InitStructure.Init.BaudRate = 115200;
USART_InitStructure.Init.WordLength = USART_WORDLENGTH_8B;
USART_InitStructure.Init.StopBits = USART_STOPBITS_1;
USART_InitStructure.Init.Parity = USART_PARITY_ODD;
USART_InitStructure.Init.Mode = USART_MODE_TX_RX;
USART_InitStructure.Init.CLKLastBit = USART_LASTBIT_ENABLE;
USART_InitStructure.Init.CLKPhase = USART_PHASE_2EDGE;
USART_InitStructure.Init.CLKPolarity = USART_POLARITY_HIGH;
USART_InitStructure.State = HAL_USART_STATE_READY;
HAL_USART_Init(&USART_InitStructure);
HAL_USART_IRQHandler(&USART_InitStructure);[/mw_shl_code]
我IO口配置如下:
[mw_shl_code=c,true]GPIO_InitStructure.Pin = GPIO_PIN_9;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
//IS_GPIO_AF(GPIO_InitStructure.Alternate);
HAL_GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_10;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
//IS_GPIO_AF(GPIO_InitStructure.Alternate);
HAL_GPIO_Init(GPIOA,&GPIO_InitStructure);[/mw_shl_code]
时钟配置如下:
[mw_shl_code=c,true]__GPIOA_CLK_ENABLE();
__USART1_CLK_ENABLE();[/mw_shl_code]
可是我在main函数中如下调用时,却返现:我没有发送数据,411芯片还在不停地发送数据,这是怎么回事呢:
[mw_shl_code=c,true]while(1)
{
HAL_USART_Receive(&USART_InitStructure, prxdata, 1, 0x5ffff);
if(*prxdata == 0x3a)
{
HAL_USART_Transmit(&USART_InitStructure, ptxdata, 1, 0x5ffff);
}
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
这个没问题,prxdata是我一直向711发送的数据,我的目的是接收到0x3a就发送回0x3a,我现在最新版v1.3.0的代码还没调通,哎
一周热门 更多>