在board_config.h文件中添加#define SOFTWARE_IIC选项用以选择使用软件IIC还是硬件IIC,如果注释掉该行则为硬件IIC方式。并完整实现软件IIC功能。

This commit is contained in:
2024-12-29 22:07:49 +08:00
parent 1a6219f2b5
commit d01f7c52e6
13 changed files with 212 additions and 122 deletions

View File

@@ -5,6 +5,10 @@
#ifndef BOARD_CONFIG_H
#define BOARD_CONFIG_H
#define SOFTWARE_IIC
// #define DEBUG_VERBOES
/******************************************************************************/
#define I2C_SPEED 20000
@@ -18,4 +22,15 @@
/******************************************************************************/
#define RS485_RCU RCU_USART0
#define RS485_GPIO_RCU RCU_GPIOA
#define RS485_GPIO_PORT GPIOA
#define RS485_TX_PIN GPIO_PIN_2
#define RS485_RX_PIN GPIO_PIN_3
#define RS485_PHY USART0
#define RS485_BAUDRATE 115200U
#define RS485_EN_PIN GPIO_PIN_1
/******************************************************************************/
#endif //BOARD_CONFIG_H

View File

@@ -19,14 +19,6 @@
/******************************************************************************/
#define I2C_SCL_HIGH() gpio_bit_set(I2C_SCL_PORT, I2C_SCL_PIN)
#define I2C_SCL_LOW() gpio_bit_reset(I2C_SCL_PORT, I2C_SCL_PIN)
#define I2C_SDA_HIGH() gpio_bit_set(I2C_SDA_PORT, I2C_SDA_PIN)
#define I2C_SDA_LOW() gpio_bit_reset(I2C_SDA_PORT, I2C_SDA_PIN)
#define I2C_SDA_READ() gpio_input_bit_get(I2C_SDA_PORT, I2C_SDA_PIN)
/******************************************************************************/
#define I2C_TIME_OUT (uint16_t)(10000)
#define I2C_OK 1
#define I2C_FAIL 0

View File

@@ -13,8 +13,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "board_config.h"
#include "soft_i2c.h"
#include "i2c.h"
/***************************************************************************/
#define LDC1612_ADDR (0x2B << 1)
/*Register Rddr*/

View File

@@ -35,6 +35,4 @@ OF SUCH DAMAGE.
#ifndef MAIN_H
#define MAIN_H
// #define DEBUG_VERBOES
#endif /* MAIN_H */

View File

@@ -13,17 +13,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
/******************************************************************************/
#define RS485_RCU RCU_USART0
#define RS485_GPIO_RCU RCU_GPIOA
#define RS485_GPIO_PORT GPIOA
#define RS485_TX_PIN GPIO_PIN_2
#define RS485_RX_PIN GPIO_PIN_3
#define RS485_PHY USART0
#define RS485_BAUDRATE 115200U
#define RS485_EN_PIN GPIO_PIN_1
#include "ldc1612.h"
#include "tmp112.h"
#include "board_config.h"
/******************************************************************************/

View File

@@ -22,6 +22,12 @@
/******************************************************************************/
#define SOFT_I2C_OK 1
#define SOFT_I2C_FAIL 0
#define SOFT_I2C_END 1
/******************************************************************************/
void soft_i2c_delay(void);
void soft_i2c_config(void);
@@ -40,4 +46,8 @@ void soft_i2c_send_byte(uint8_t data);
uint8_t soft_i2c_receive_byte(uint8_t ack);
uint8_t soft_i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2]);
uint8_t soft_i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data);
#endif //SOFT_I2C_H

View File

@@ -13,7 +13,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "board_config.h"
#ifdef SOFTWARE_IIC
#include "soft_i2c.h"
#else
#include "i2c.h"
#endif
/******************************************************************************/