123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- /************************************************************************************************/
- /**
- * @file i2c_bsp.h
- * @author MCU Ecosystem Development Team
- * @brief I2C BSP头文件。
- *
- *
- **************************************************************************************************
- * @attention
- * Copyright (c) CEC Huada Electronic Design Co.,Ltd. All rights reserved.
- *
- **************************************************************************************************
- */
- /* 避免头文件重复引用 */
- #ifndef I2C_BSP_H
- #define I2C_BSP_H
- #include "ciu32f003_std.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*------------------------------------------includes--------------------------------------------*/
- /*-------------------------------------------define---------------------------------------------*/
- /* I2C延时操作 */
- #define CLK_DELAY (16U)
- #define ACK_DELAY (6U)
- #define USER_DELAY (5U) //
- /* I2C返回ACK的类型 */
- #define RET_ACK (0x00000000U)
- #define RET_NACK (0x00000001U)
- /* I2C主机读写请求 */
- #define REQ_WRITE (0U)
- #define REQ_READ (1U)
- /*------------------------------------------- io_set ------------------------------------------*/
- #define IIC_SCL_PA0 1U
- #define IIC_SCL_PA1 2U
- #define IIC_SCL_PA2 3U
- #define IIC_SCL_PA3 4U
- #define IIC_SCL_PA4 5U
- #define IIC_SCL_PA5 6U
- #define IIC_SCL_PA6 7U
- #define IIC_SCL_PA7 8U
- #define IIC_SCL_PB0 9U
- #define IIC_SCL_PB1 10U
- #define IIC_SCL_PB2 11U
- #define IIC_SCL_PB3 12U
- #define IIC_SCL_PB4 13U
- #define IIC_SCL_PB5 14U
- #define IIC_SCL_PB6 15U
- #define IIC_SCL_PB7 16U
- #define IIC_SCL_PC0 17U
- #define IIC_SCL_PC1 18U
- #define IIC_SDA_PA0 1U
- #define IIC_SDA_PA1 2U
- #define IIC_SDA_PA2 3U
- #define IIC_SDA_PA3 4U
- #define IIC_SDA_PA4 5U
- #define IIC_SDA_PA5 6U
- #define IIC_SDA_PA6 7U
- #define IIC_SDA_PA7 8U
-
- #define IIC_SDA_PB0 9U
- #define IIC_SDA_PB1 10U
- #define IIC_SDA_PB2 11U
- #define IIC_SDA_PB3 12U
- #define IIC_SDA_PB4 13U
- #define IIC_SDA_PB5 14U
- #define IIC_SDA_PB6 15U
- #define IIC_SDA_PB7 16U
-
- #define IIC_SDA_PC0 17U
- #define IIC_SDA_PC1 18U
- #define IIC_PULLUP_NULL 0U
- #define IIC_PULLUP 1U
- /*-------------------------------------------functions-内部iic接口-----------------------------------------*/
- static void bsp_i2c_generate_start(void);
- static void bsp_i2c_generate_stop(void);
- static void bsp_i2c_generate_ack(uint32_t ack_type);
- static uint32_t bsp_i2c_master_send_byte(uint8_t data);
- static uint8_t bsp_i2c_master_receive_byte(void);
- /*-------------------------------------------functions-----用户iic接口-------------------------------------*/
- void SN_IIC_IO_set(uint8_t SCL_PIN_x ,uint8_t SDA_PIN_x ,uint8_t PULLUP ); //设置iic要使用的通信引脚
- void SN_IIC_slave(uint8_t iic_slave_id ); //设置从机id
- void SN_IIC_ERROR_call(void (*error_call) (void)); //设置通信错误处理
- void bsp_i2c_master_send(uint8_t * g_tx_buffer , uint16_t BUFF_SIZE); //主机发送数据
- void bsp_i2c_master_receive(uint8_t * g_rx_buffer,uint16_t BUFF_SIZE); //主机接收数据
- #ifdef __cplusplus
- }
- #endif
- #endif /* I2C_BSP_H */
|