generated from hulk/gd32e23x_template
在board_config.h文件中添加#define SOFTWARE_IIC选项用以选择使用软件IIC还是硬件IIC,如果注释掉该行则为硬件IIC方式。并完整实现软件IIC功能。
This commit is contained in:
@@ -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
|
||||
|
@@ -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*/
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
Reference in New Issue
Block a user