调试了2天,串口接收怎么都调不通,头大,求大神帮忙。还有顺便问一下这个芯片的系统时钟怎么看,不知道怎么跳定时器的分频那些。代码贴到下面
void Usart_Camera_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO TX/RX clock */
__HAL_RCC_GPIOA_CLK_ENABLE();
/* Enable USART1 clock */
__HAL_RCC_USART1_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* UART TX GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* UART RX GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP ;
GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_USART_DeInit(&USART1_HandleStructure);
USART1_HandleStructure.Instance = USART1;
USART1_HandleStructure.Init.BaudRate = 115200; //2¨ìØÂê
USART1_HandleStructure.Init.WordLength = USART_WORDLENGTH_8B; //×Ö3¤8λ
USART1_HandleStructure.Init.StopBits = USART_STOPBITS_1; //ò»¸öí£Ö1λ
USART1_HandleStructure.Init.Parity = USART_PARITY_NONE; //ÎTÆæżD£Ñé
USART1_HandleStructure.Init.Mode = USART_MODE_TX_RX; //êÕ·¢Ä£ê½
HAL_USART_Init(&USART1_HandleStructure);
__HAL_USART_ENABLE(&USART1_HandleStructure);
/*##-3- Configure the NVIC for UART ########################################*/
/* NVIC for USART1 */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USART1_IRQn);
__HAL_USART_ENABLE_IT(&USART1_HandleStructure, USART_IT_RXNE);
//__HAL_USART_ENABLE_IT(&USART1_HandleStructure, USART_IT_TC);
//HAL_USART_Receive_IT(&USART1_HandleStructure, (u32)Usart1_Rxbuffer, 1);
}
void USART1_IRQHandler(void)
{
u8 data;
Work_Led_On();
//Work_Led_Off();
//Send_Data_To_Camera((u8*)"nima",4);
if (__HAL_USART_GET_IT(&USART1_HandleStructure, USART_IT_TC) != RESET)
{
//__HAL_USART_CLEAR_IT(&USART1_HandleStructure, USART_CLEAR_TCF);
//Send_Data_To_Camera((u8*)"nima", 4);
}
if (__HAL_USART_GET_IT(&USART1_HandleStructure, USART_IT_RXNE) != RESET)
{
data = USART1->RDR;
Send_Data_To_Camera((u8*)"wocao", 5);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
你通过什么来看接收现象的?一般是串口接收中断吧,
串口中断,接收缓冲区内的数据
你先看看串口接收在看DMA接收呢,一步步的调试。直接看串口接收寄存器,你发一个看看是不是跟着变的。。你这代码主循环一直设置接收BUFF的长度(我没看HAL库函数的函数原型),会不会将接收到的值重复存储在数组的前面几位。。。。好像是没设置一次接收长度,就会从头开始是不是?
一周热门 更多>