48 lines
1.8 KiB
C
48 lines
1.8 KiB
C
|
#ifndef __IIC_H
|
|||
|
#define __IIC_H
|
|||
|
|
|||
|
#include "bsp_delay.h"
|
|||
|
#include "drv_sys.h"
|
|||
|
#include "bsp_iic.h"
|
|||
|
|
|||
|
|
|||
|
/******************************************************************************************/
|
|||
|
/* <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> */
|
|||
|
|
|||
|
#define IIC_SCL_GPIO_PORT GPIOB
|
|||
|
#define IIC_SCL_GPIO_PIN GPIO_PIN_6
|
|||
|
#define IIC_SCL_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOB_CLK_ENABLE(); }while(0) /* PB<50><42>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9> */
|
|||
|
|
|||
|
#define IIC_SDA_GPIO_PORT GPIOB
|
|||
|
#define IIC_SDA_GPIO_PIN GPIO_PIN_7
|
|||
|
#define IIC_SDA_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOB_CLK_ENABLE(); }while(0) /* PB<50><42>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9> */
|
|||
|
|
|||
|
/******************************************************************************************/
|
|||
|
|
|||
|
/* IO<49><4F><EFBFBD><EFBFBD> */
|
|||
|
#define IIC_SCL(x) do{ x ? \
|
|||
|
HAL_GPIO_WritePin(IIC_SCL_GPIO_PORT, IIC_SCL_GPIO_PIN, GPIO_PIN_SET) : \
|
|||
|
HAL_GPIO_WritePin(IIC_SCL_GPIO_PORT, IIC_SCL_GPIO_PIN, GPIO_PIN_RESET); \
|
|||
|
}while(0) /* SCL */
|
|||
|
|
|||
|
#define IIC_SDA(x) do{ x ? \
|
|||
|
HAL_GPIO_WritePin(IIC_SDA_GPIO_PORT, IIC_SDA_GPIO_PIN, GPIO_PIN_SET) : \
|
|||
|
HAL_GPIO_WritePin(IIC_SDA_GPIO_PORT, IIC_SDA_GPIO_PIN, GPIO_PIN_RESET); \
|
|||
|
}while(0) /* SDA */
|
|||
|
|
|||
|
#define IIC_READ_SDA HAL_GPIO_ReadPin(IIC_SDA_GPIO_PORT, IIC_SDA_GPIO_PIN) /* <20><>ȡSDA */
|
|||
|
|
|||
|
|
|||
|
/* IIC<49><43><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
void iic_init(void); /* <20><>ʼ<EFBFBD><CABC>IIC<49><43>IO<49><4F> */
|
|||
|
void iic_start(void); /* <20><><EFBFBD><EFBFBD>IIC<49><43>ʼ<EFBFBD>ź<EFBFBD> */
|
|||
|
void iic_stop(void); /* <20><><EFBFBD><EFBFBD>IICֹͣ<CDA3>ź<EFBFBD> */
|
|||
|
void iic_ack(void); /* IIC<49><43><EFBFBD><EFBFBD>ACK<43>ź<EFBFBD> */
|
|||
|
void iic_nack(void); /* IIC<49><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ACK<43>ź<EFBFBD> */
|
|||
|
uint8_t iic_wait_ack(void); /* IIC<49>ȴ<EFBFBD>ACK<43>ź<EFBFBD> */
|
|||
|
void iic_send_byte(uint8_t txd);/* IIC<49><43><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD> */
|
|||
|
uint8_t iic_read_byte(unsigned char ack);/* IIC<49><43>ȡһ<C8A1><D2BB><EFBFBD>ֽ<EFBFBD> */
|
|||
|
|
|||
|
#endif
|
|||
|
|