STM32 HAL API functions (1) - basic
HAL stands for Hardware Abstraction Layer. It's generic API by ST Microtronics to program their MCUs.
/* delay */
HAL_Delay(1000);
/* GPIO */
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); // set HI
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); // set LO
/* UART */
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
/* I2C */ // example: TMP102
HAL_StatusTypeDef ret; // expect HAL_OK if operation is successful
// set request argument in buf[0], then:
ret = HAL_I2C_Master_Transit(&h12c1, TMP102_ADR, buf, 1, HAL_MAX_DELAY);
ret = HAL_I2C_Master_Receive(&h12c1, TMP102_ADR, buf, 2, HAL_MAX_DELAY);
/* ADC */
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
uint16_t raw;
raw = HAL_ADC_GetValue(&hadc1);
0 Comments:
Post a Comment
<< Home