149 lines
4.4 KiB
C
149 lines
4.4 KiB
C
|
/**
|
|||
|
******************************************************************************
|
|||
|
* @file main.c
|
|||
|
* @author fire
|
|||
|
* @version V1.0
|
|||
|
* @date 2019-xx-xx
|
|||
|
* @brief AP3216C <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>
|
|||
|
******************************************************************************
|
|||
|
* @attention
|
|||
|
*
|
|||
|
* ʵ<EFBFBD><EFBFBD>ƽ̨:Ұ<EFBFBD><EFBFBD> STM32 H750 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>̳ :http://www.firebbs.cn
|
|||
|
* <EFBFBD>Ա<EFBFBD> :http://firestm32.taobao.com
|
|||
|
*
|
|||
|
******************************************************************************
|
|||
|
*/
|
|||
|
|
|||
|
#include "main.h"
|
|||
|
#include "stm32h7xx.h"
|
|||
|
#include "./usart/bsp_debug_usart.h"
|
|||
|
#include "./led/bsp_led.h"
|
|||
|
#include "./delay/core_delay.h"
|
|||
|
#include "./i2c/bsp_i2c.h"
|
|||
|
#include "./ap3216c/ap3216c.h"
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param <EFBFBD><EFBFBD>
|
|||
|
* @retval <EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
int main(void)
|
|||
|
{
|
|||
|
/**/
|
|||
|
static uint16_t ALS_RAW;
|
|||
|
static uint16_t PS_RAW;
|
|||
|
static uint16_t IR_RAW;
|
|||
|
|
|||
|
float ALSValue;
|
|||
|
|
|||
|
HAL_Init();
|
|||
|
/* <20><><EFBFBD><EFBFBD>ϵͳʱ<CDB3><CAB1>Ϊ480 MHz */
|
|||
|
SystemClock_Config();
|
|||
|
|
|||
|
LED_GPIO_Config();
|
|||
|
/* <20><>ʼ<EFBFBD><CABC><EFBFBD>ں<EFBFBD><DABA><EFBFBD>ʱ */
|
|||
|
HAL_InitTick(5);
|
|||
|
/*<2A><>ʼ<EFBFBD><CABC>USART <20><><EFBFBD><EFBFBD>ģʽΪ 115200 8-N-1<><31><EFBFBD>жϽ<D0B6><CFBD><EFBFBD>*/
|
|||
|
DEBUG_USART_Config();
|
|||
|
|
|||
|
printf("\r\n <20><>ӭʹ<D3AD><CAB9>Ұ<EFBFBD><D2B0> STM32 H743 <20><><EFBFBD><EFBFBD><EFBFBD>塣\r\n");
|
|||
|
printf("\r\n <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> \r\n");
|
|||
|
|
|||
|
printf(" оƬ<D0BE><C6AC>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>.....\n");
|
|||
|
/* <20><>ʼ<EFBFBD><CABC> <20><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
AP3216C_Init();
|
|||
|
|
|||
|
while(1)
|
|||
|
{
|
|||
|
AP3216CReadALS(&ALS_RAW);
|
|||
|
AP3216CReadPS(&PS_RAW);
|
|||
|
AP3216CReadIR(&IR_RAW);
|
|||
|
ALSValue = ALS_RAW * 0.36;// Lux = 16 bit ALS data * Resolution
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣺%.2flux ",ALSValue);
|
|||
|
printf("<EFBFBD>ӽ<EFBFBD>ֵ<EFBFBD><EFBFBD>%d ",PS_RAW);
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣺%d\r\n",IR_RAW);
|
|||
|
|
|||
|
LED2_TOGGLE;
|
|||
|
HAL_Delay(225);//<2F><>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>225ms
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @brief System Clock <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* system Clock <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
|||
|
* System Clock source = PLL (HSE)
|
|||
|
* SYSCLK(Hz) = 480000000 (CPU Clock)
|
|||
|
* HCLK(Hz) = 240000000 (AXI and AHBs Clock)
|
|||
|
* AHB Prescaler = 2
|
|||
|
* D1 APB3 Prescaler = 2 (APB3 Clock 120MHz)
|
|||
|
* D2 APB1 Prescaler = 2 (APB1 Clock 120MHz)
|
|||
|
* D2 APB2 Prescaler = 2 (APB2 Clock 120MHz)
|
|||
|
* D3 APB4 Prescaler = 2 (APB4 Clock 120MHz)
|
|||
|
* HSE Frequency(Hz) = 25000000
|
|||
|
* PLL_M = 5
|
|||
|
* PLL_N = 192
|
|||
|
* PLL_P = 2
|
|||
|
* PLL_Q = 2
|
|||
|
* PLL_R = 2
|
|||
|
* VDD(V) = 3.3
|
|||
|
* Flash Latency(WS) = 4
|
|||
|
* @param None
|
|||
|
* @retval None
|
|||
|
*/
|
|||
|
/**
|
|||
|
* @brief System Clock Configuration
|
|||
|
* @retval None
|
|||
|
*/
|
|||
|
void SystemClock_Config(void)
|
|||
|
{
|
|||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|||
|
|
|||
|
/** Supply configuration update enable
|
|||
|
*/
|
|||
|
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
|||
|
/** Configure the main internal regulator output voltage
|
|||
|
*/
|
|||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
|
|||
|
|
|||
|
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
|
|||
|
/** Initializes the CPU, AHB and APB busses clocks
|
|||
|
*/
|
|||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|||
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|||
|
RCC_OscInitStruct.PLL.PLLM = 5;
|
|||
|
RCC_OscInitStruct.PLL.PLLN = 192;
|
|||
|
RCC_OscInitStruct.PLL.PLLP = 2;
|
|||
|
RCC_OscInitStruct.PLL.PLLQ = 2;
|
|||
|
RCC_OscInitStruct.PLL.PLLR = 2;
|
|||
|
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
|||
|
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
|||
|
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
|||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|||
|
{
|
|||
|
}
|
|||
|
/** Initializes the CPU, AHB and APB busses clocks
|
|||
|
*/
|
|||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|
|||
|
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
|
|||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|||
|
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
|||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
|
|||
|
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
|
|||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
|
|||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
|||
|
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
|||
|
|
|||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
|||
|
{
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|