GeBalanceBot/Hardware/Firmware/GeBalanceBot_Firmware v1.0/DRV/bsp_iic.h

63 lines
1.8 KiB
C
Raw Normal View History

2024-01-18 01:55:04 +08:00
#ifndef __BSP_IIC_H
#define __BSP_IIC_H
#include "stm32f10x.h"
/* <20><><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>GPIO<49>˿<EFBFBD>, <20>û<EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EBBCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>SCL<43><4C>SDA<44><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define GPIO_PORT_I2C GPIOB /* GPIO<49>˿<EFBFBD> */
#define RCC_I2C_PORT RCC_APB2Periph_GPIOB /* GPIO<49>˿<EFBFBD>ʱ<EFBFBD><CAB1> */
#define I2C_SCL_PIN GPIO_Pin_10 /* <20><><EFBFBD>ӵ<EFBFBD>SCLʱ<4C><CAB1><EFBFBD>ߵ<EFBFBD>GPIO */
#define I2C_SDA_PIN GPIO_Pin_11 /* <20><><EFBFBD>ӵ<EFBFBD>SDA<44><41><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>GPIO */
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дSCL<43><4C>SDA<44>ĺ꣬<C4BA><EAA3AC><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ֲ<EFBFBD>ԺͿ<D4BA><CDBF>Ķ<EFBFBD><C4B6><EFBFBD> */
#if 1 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺 1 ѡ<><D1A1>GPIO<49>Ŀ⺯<C4BF><E2BAAF>ʵ<EFBFBD><CAB5>IO<49><4F>д */
#define I2C_SCL_1() GPIO_SetBits(GPIO_PORT_I2C, I2C_SCL_PIN) /* SCL = 1 */
#define I2C_SCL_0() GPIO_ResetBits(GPIO_PORT_I2C, I2C_SCL_PIN) /* SCL = 0 */
#define I2C_SDA_1() GPIO_SetBits(GPIO_PORT_I2C, I2C_SDA_PIN) /* SDA = 1 */
#define I2C_SDA_0() GPIO_ResetBits(GPIO_PORT_I2C, I2C_SDA_PIN) /* SDA = 0 */
#define I2C_SDA_READ() GPIO_ReadInputDataBit(GPIO_PORT_I2C, I2C_SDA_PIN) /* <20><>SDA<44><41><EFBFBD><EFBFBD>״̬ */
#else /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧ѡ<D6A7><D1A1>ֱ<EFBFBD>ӼĴ<D3BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>IO<49><4F>д */
/*<2A><>ע<EFBFBD><EFBFBD><E2A3BA><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IAR<41><52><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD>Ż<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><E1B1BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD> */
#define I2C_SCL_1() GPIO_PORT_I2C->BSRR = I2C_SCL_PIN /* SCL = 1 */
#define I2C_SCL_0() GPIO_PORT_I2C->BRR = I2C_SCL_PIN /* SCL = 0 */
#define I2C_SDA_1() GPIO_PORT_I2C->BSRR = I2C_SDA_PIN /* SDA = 1 */
#define I2C_SDA_0() GPIO_PORT_I2C->BRR = I2C_SDA_PIN /* SDA = 0 */
#define I2C_SDA_READ() ((GPIO_PORT_I2C->IDR & I2C_SDA_PIN) != 0) /* <20><>SDA<44><41><EFBFBD><EFBFBD>״̬ */
#endif
#include <inttypes.h>
#define I2C_WR 0 /* д<><D0B4><EFBFBD><EFBFBD>bit */
#define I2C_RD 1 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bit */
void i2c_Delay(void);
void IIC_Init(void);
void IIC_Start(void);
void IIC_Stop(void);
void IIC_Send_Byte(uint8_t _ucByte);
uint8_t IIC_Read_Byte(u8 ack);
uint8_t IIC_Wait_Ack(void);
void IIC_Ack(void);
void IIC_NAck(void);
uint8_t i2c_CheckDevice(uint8_t _Address);
#endif