1_GPIO
HAL_GPIO_WritePin(GPIOx,GPIO_PIN_x,GPIO_PIN_SET); //或者GPIO_PIN_RESET
2_PWM
uint16_t val = 0;
HAL_TIM_PWM_Start(&htimx,TIM_CHANNEL_1);
While(){
_HAL_TIM_SET_COMPARE(&htimx,TIM_CHANNEL_1,val);
_val++;
}
3_UART_发送10字符串,仅执行1次(不在while中)
//定义两个数组变量
Uint8_t T[]=”\nPlease enter 10 characters:\r\n”;
Uint8_t R[20];
//串口中断发送/接收aTxStartMessage数组,并存于R中
HAL_UART_Transmit_IT(&huart1,(uint8_t*)T,Sizeof(T));
HAL_UART_Receive_IT(&huart1,(uint8_t*)R,10);
//函数将接收到的数据用串口发送回去
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
HAL_UART_Transmit(&huart1,(uint8_t*)R,10,0xFFFF);
}
1 串口发送/接收函数
串口轮询模式发送/接收,使用超时管理机制
HAL_UART_Transmit();
HAL_UART_Receive ();
串口中断模式发送/接收
HAL_UART_Transmit_IT();
HAL_UART_Receive_IT();
例:
main.c:
uint8_t aRxBuffer[RXBUFFERSIZE];
__HAL_UART_ENABLE_IT(&huart7,UART_IT_RXNE);
网友评论