53 lines
2.1 KiB
C
53 lines
2.1 KiB
C
#ifndef __I2C_H
|
|
#define __I2C_H
|
|
|
|
#include "stm32h7xx.h"
|
|
|
|
extern I2C_HandleTypeDef I2C_Handle;
|
|
|
|
/* 这个地址只要与STM32外挂的I2C器件地址不一样即可 */
|
|
#define I2C_OWN_ADDRESS7 0X0A
|
|
|
|
#define I2Cx_FLAG_TIMEOUT ((uint32_t) 1000) //0x1100
|
|
#define I2Cx_LONG_TIMEOUT ((uint32_t) (300 * I2Cx_FLAG_TIMEOUT)) //was300
|
|
|
|
#define I2Cx I2C1
|
|
#define I2Cx_CLK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE()
|
|
#define I2Cx_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
|
#define I2Cx_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
|
|
|
#define I2Cx_FORCE_RESET() __HAL_RCC_I2C1_FORCE_RESET()
|
|
#define I2Cx_RELEASE_RESET() __HAL_RCC_I2C1_RELEASE_RESET()
|
|
|
|
/* Definition for I2Cx Pins */
|
|
#define I2Cx_SCL_PIN GPIO_PIN_8
|
|
#define I2Cx_SCL_GPIO_PORT GPIOB
|
|
#define I2Cx_SCL_AF GPIO_AF4_I2C1
|
|
#define I2Cx_SDA_PIN GPIO_PIN_9
|
|
#define I2Cx_SDA_GPIO_PORT GPIOB
|
|
#define I2Cx_SDA_AF GPIO_AF4_I2C1
|
|
|
|
/*信息输出*/
|
|
#define EEPROM_DEBUG_ON 0
|
|
|
|
#define EEPROM_INFO(fmt,arg...) printf("<<-EEPROM-INFO->> "fmt"\n",##arg)
|
|
#define EEPROM_ERROR(fmt,arg...) printf("<<-EEPROM-ERROR->> "fmt"\n",##arg)
|
|
#define EEPROM_DEBUG(fmt,arg...) do{\
|
|
if(EEPROM_DEBUG_ON)\
|
|
printf("<<-EEPROM-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
|
|
}while(0)
|
|
|
|
/* 函数声明 */
|
|
|
|
void I2C_Mode_Config(void);
|
|
int Sensors_I2C_ReadRegister(unsigned char slave_addr,
|
|
unsigned char reg_addr,
|
|
unsigned short len,
|
|
unsigned char *data_ptr);
|
|
int Sensors_I2C_WriteRegister(unsigned char slave_addr,
|
|
unsigned char reg_addr,
|
|
unsigned short len,
|
|
unsigned char *data_ptr);
|
|
|
|
#endif /* __I2C_H */
|