void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){3. 烧录并运行
GPIO_PinState b7_pin = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7); // 读取b7的状态
b7_pin=1-b0_pin;
switch (GPIO_Pin){//判断引脚
case GPIO_PIN_7:
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2,1-b0_pin); // 将a2写入与b7相同的电位
break;
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)最后在main函数里面加入以下中断函数
{
if(Uart1_Rx_Cnt >= 255) //溢出判断
{
Uart1_Rx_Cnt = 0;
memset(Uart1_RxBuff,0x00,sizeof(Uart1_RxBuff));
HAL_UART_Transmit(&huart1, (uint8_t *)&cAlmStr, sizeof(cAlmStr),0xFFFF);
}
else
{
Uart1_RxBuff[Uart1_Rx_Cnt++] = aRxBuffer; //接收数据转存
if((Uart1_RxBuff[Uart1_Rx_Cnt-1] == 0x0A)||(Uart1_RxBuff[Uart1_Rx_Cnt-2] == 0x0D)) //判断结束位
{
HAL_UART_Transmit(&huart1, (uint8_t *)&Uart1_RxBuff, Uart1_Rx_Cnt,0xFFFF); //将收到的信息发送出去
Uart1_Rx_Cnt = 0;
memset(Uart1_RxBuff,0x00,sizeof(Uart1_RxBuff)); //清空数组
}
}
HAL_UART_Receive_IT(&huart1, (uint8_t *)&aRxBuffer, 1); //再开启接收中断
}
HAL_Init();3 最后进行烧录,然后在野火串口助手里面进行手动输入数据结果如下
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
//接收中断函数
HAL_UART_Receive_IT(&huart1,(uint8_t*)&aRxBuffer,1);
uint8_t send_char[;然后对hex文件进行烧录,并进行运行结果如下
HAL_UART_Transmit_DMA(&huart1,(uint8_t *)send_char,0xc);
HAL_Delay(500);
更多回帖