延迟函数

    毫秒级延迟
1
HAL_Delay(uint32_t Delay)
uint32_t Delay:  This parameter can be (0..2^32)
retval:          None

GPIO口控制

多个IO口设置同样的状态,可以使用 '|' 连接

GPIO_Write

1
HAL_GPIO_WritePin(GPIOx, GPIO_Pin, PinState) 
GPIOx:         where x can be (A..G depending on device used)
GPIO_Pin :     This parameter can be one of GPIO_PIN_x where x can be (0..15)
PinState :     This parameter can be one of the GPIO_PinState enum values:
                1    GPIO_PIN_RESET: to clear the port pin  (0)
                2    GPIO_PIN_SET: to set the port pin      (1)
retval:     None

GPIO_Read

1
HAL_GPIO_ReadPin(GPIOx, GPIO_Pin) 
GPIOx:         where x can be (A..G depending on device used)
GPIO_Pin :     This parameter can be one of GPIO_PIN_x where x can be (0..15)
retval:        1    GPIO_PIN_RESET        (0)
               2    GPIO_PIN_SET      (1)

USART

USART_Send

1
2
3
4
5
6
7
8
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)

* @param huart Pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
* @param pData Pointer to data buffer (u8 or u16 data elements).
* @param Size Amount of data elements (u8 or u16) to be sent
* @param Timeout Timeout duration
* @retval HAL status
HAL_UART_Transmit(&huart1, (uint8_t*)&"Hello\r\n", 7, 0xffff);

USART_receive

1
2
3
4
5
6
7
8
HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)

* @param huart Pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
* @param pData Pointer to data buffer (u8 or u16 data elements).
* @param Size Amount of data elements (u8 or u16) to be received.
* @param Timeout Timeout duration
* @retval HAL status
HAL_UART_Receive_IT(&huart3,(uint8_t *)&USART1_NewData,1);

ADC

ADC校准

1
2
3
4
5
HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc); //先校准ADC
* @param hadc: This parameter can be
1 &hadc1
2 &hadc2
* @retval HAL status
  例子:
  HAL_ADCEx_Calibration_Start(&hadc1);
  

软件开启一次转换

1
2
3
4
5
6
7
8
9
10
uint16_t ADC_IN_1(void) //ADC采集程序
{
HAL_ADC_Start(&hadc1); //开始ADC采集
HAL_ADC_PollForConversion(&hadc1,500); //等待采集结束
if(HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1), HAL_ADC_STATE_REG_EOC)) //读取ADC完成标志位
{
return HAL_ADC_GetValue(&hadc1); //读出ADC数值
}
return 0;
}

DMA连续转换

1
2
3
4
5
6
7
8
HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)

* @param hadc: ADC handle
* @param pData: The destination Buffer address.
* @param Length: The length of data to be transferred from ADC peripheral to memory.
* @retval None

DMA must be configured to transfer size: half word.
例子:
 HAL_ADC_Start_DMA(&hadc1, (uint32_t *) & a1, 1); 
 adc1   转入a1中  每次连续转换1个

SPI

1
2
3
4
5
6
7
8
9
HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size,uint32_t Timeout)

* @param hspi pointer to a SPI_HandleTypeDef structure that contains
* the configuration information for SPI module.
* @param pTxData pointer to transmission data buffer
* @param pRxData pointer to reception data buffer
* @param Size amount of data to be sent and received
* @param Timeout Timeout duration
* @retval HAL status