首先对寄存器地址进行宏定义
MAX44009_Reg.h
#ifndef _MAX44009_REG_H
#define _MAX44009_REG_H
#define MAX44009_Interupt_Status 0x00
#define MAX44009_Interrupt_Enable 0x01
#define MAX44009_Configuration 0x02
#define MAX44009_Lux_High_Byte 0x03
#define MAX44009_Lux_Low_Byte 0x04
#define MAX44009_Upper_Threshold_High_Byte 0x05
#define MAX44009_Lower_Threshold_High_Byte 0x06
#define MAX44009_Threshold_Timer 0x07
#endif
然后写MAX44009.c文件
#include "stm32f10x.h" // Device header
#include"MAX44009_Reg.h"
#include<math.h>
#define MAX44009_ADDRESS 0x94
void MAX44009_WaitEvent(I2C_TypeDef*I2Cx , uint32_t I2C_EVENT) //等待EV时间结束
{
uint32_t Timeout;
Timeout = 100000;
while (I2C_CheckEvent(I2Cx,I2C_EVENT) != SUCCESS)
{
Timeout --;
if (Timeout =&