| | |
| | | /* USER CODE END Header */ |
| | | /* Includes ------------------------------------------------------------------*/ |
| | | #include "main.h" |
| | | #include "adc.h" |
| | | #include "tim.h" |
| | | #include "usart.h" |
| | | #include "gpio.h" |
| | | |
| | | /* Private includes ----------------------------------------------------------*/ |
| | | /* USER CODE BEGIN Includes */ |
| | | #include "ds18b20.h" |
| | | |
| | | /* USER CODE END Includes */ |
| | | |
| | | /* Private typedef -----------------------------------------------------------*/ |
| | |
| | | int main(void) |
| | | { |
| | | /* USER CODE BEGIN 1 */ |
| | | int rv; |
| | | float temperature; |
| | | uint32_t lux, noisy; |
| | | /* USER CODE END 1 */ |
| | | |
| | | /* MCU Configuration--------------------------------------------------------*/ |
| | |
| | | MX_GPIO_Init(); |
| | | MX_USART1_UART_Init(); |
| | | MX_TIM4_Init(); |
| | | MX_ADC1_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | |
| | | /* USER CODE END 2 */ |
| | |
| | | { |
| | | sysled_hearbeat(); |
| | | |
| | | if( 0 != (rv=ds18b20_get_temperature(&temperature)) ) |
| | | { |
| | | printf("ERROR: DS18B20 sample temperature failure, rv: %d\r\n", rv); |
| | | continue; |
| | | } |
| | | adc_sample_lux_noisy(&lux, &noisy); |
| | | printf("Lux[%lu] Noisy[%lu]\r\n", lux, noisy); |
| | | |
| | | printf("DS18B20 sample temperature %.2f\r\n", temperature); |
| | | HAL_Delay(5000); |
| | | |
| | | /* USER CODE END WHILE */ |
| | | |
| | |
| | | { |
| | | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| | | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| | | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
| | | |
| | | /** Initializes the RCC Oscillators according to the specified parameters |
| | | * in the RCC_OscInitTypeDef structure. |
| | |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; |
| | | PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; |
| | | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | } |
| | | |
| | | /* USER CODE BEGIN 4 */ |