151 lines
4.4 KiB
C
151 lines
4.4 KiB
C
/**
|
||
******************************************************************************
|
||
* @file main.c
|
||
* @author fire
|
||
* @version V1.0
|
||
* @date 2019-xx-xx
|
||
* @brief AP3216C 读光照实验
|
||
******************************************************************************
|
||
* @attention
|
||
*
|
||
* 实验平台:野火 STM32 H750 开发板
|
||
* 论坛 :http://www.firebbs.cn
|
||
* 淘宝 :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 主函数
|
||
* @param 无
|
||
* @retval 无
|
||
*/
|
||
int main(void)
|
||
{
|
||
/**/
|
||
static uint16_t ALS_RAW;
|
||
static uint16_t PS_RAW;
|
||
static uint16_t IR_RAW;
|
||
|
||
float ALSValue;
|
||
|
||
HAL_Init();
|
||
/* 配置系统时钟为480 MHz */
|
||
SystemClock_Config();
|
||
/* 打开ICache */
|
||
SCB_EnableICache();
|
||
|
||
LED_GPIO_Config();
|
||
/* 初始化内核延时 */
|
||
HAL_InitTick(5);
|
||
/*初始化USART 配置模式为 115200 8-N-1,中断接收*/
|
||
DEBUG_USART_Config();
|
||
|
||
printf("\r\n 欢迎使用野火 STM32 H743 开发板。\r\n");
|
||
printf("\r\n 这是一个三合一光照传感器测试例程 \r\n");
|
||
|
||
printf(" 芯片初始化中.....\n");
|
||
/* 初始化 光照传感器 */
|
||
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("环境光:%.2flux ",ALSValue);
|
||
printf("接近值:%d ",PS_RAW);
|
||
printf("红外光:%d\r\n",IR_RAW);
|
||
|
||
LED2_TOGGLE;
|
||
HAL_Delay(225);//最小采样间隔225ms
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* @brief System Clock 配置
|
||
* system Clock 配置如下:
|
||
* 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****/
|