mirror of
https://github.com/Arthur-cai/Soft_I2C_Driver.git
synced 2025-06-17 13:07:53 +00:00
fix(软件模拟I2C):修复读数据错误、宏定义缺失,新增测试GD32F305ZE
1. 调整读取数据的时序,修复读取第一个bit出错的问题 2. 添加 bsp_soft_i2c_private.h 文件内缺失的宏定义 3. 增加GD32F305ZE核心板测试波形 4. 按修改后的驱动重新测试了GD32F303RE和STM32F103C8的波形 Signed-off-by: ArthurCai <arthurcai_c@163.com>
This commit is contained in:
parent
3d500401a9
commit
3921acd5c7
@ -327,6 +327,7 @@ static soft_i2c_err_t soft_i2c_read_byte(P_SOFT_I2C_T p_i2c, uint8_t *p_data) {
|
|||||||
#endif
|
#endif
|
||||||
soft_i2c_write_gpio(&p_i2c->sda, SOFT_I2C_LEVEL_HIGH); // 开启线与
|
soft_i2c_write_gpio(&p_i2c->sda, SOFT_I2C_LEVEL_HIGH); // 开启线与
|
||||||
for (loopCnt = 0; loopCnt < 8; loopCnt++) {
|
for (loopCnt = 0; loopCnt < 8; loopCnt++) {
|
||||||
|
soft_i2c_delay_us();
|
||||||
*p_data <<= 1;
|
*p_data <<= 1;
|
||||||
soft_i2c_write_gpio(&p_i2c->scl, SOFT_I2C_LEVEL_HIGH); // 拉起SCL
|
soft_i2c_write_gpio(&p_i2c->scl, SOFT_I2C_LEVEL_HIGH); // 拉起SCL
|
||||||
#if defined(__SOFT_I2C_CLOCK_STRECH_EN__)
|
#if defined(__SOFT_I2C_CLOCK_STRECH_EN__)
|
||||||
@ -341,9 +342,9 @@ static soft_i2c_err_t soft_i2c_read_byte(P_SOFT_I2C_T p_i2c, uint8_t *p_data) {
|
|||||||
*p_data |= soft_i2c_read_gpio(&p_i2c->sda); // 读取数据
|
*p_data |= soft_i2c_read_gpio(&p_i2c->sda); // 读取数据
|
||||||
soft_i2c_delay_800ns();
|
soft_i2c_delay_800ns();
|
||||||
soft_i2c_write_gpio(&p_i2c->scl, SOFT_I2C_LEVEL_LOW); // 拉低SCL
|
soft_i2c_write_gpio(&p_i2c->scl, SOFT_I2C_LEVEL_LOW); // 拉低SCL
|
||||||
soft_i2c_delay_us();
|
|
||||||
}
|
}
|
||||||
soft_i2c_write_gpio(&p_i2c->sda, SOFT_I2C_LEVEL_LOW); // 关闭线与
|
soft_i2c_write_gpio(&p_i2c->sda, SOFT_I2C_LEVEL_LOW); // 关闭线与
|
||||||
|
soft_i2c_delay_800ns();
|
||||||
return SOFT_I2C_ERR_OK;
|
return SOFT_I2C_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#elif defined(STM32F10X_HD) || defined(STM32F10X_MD) || defined(STM32F10X_CL)
|
#elif defined(STM32F10X_HD) || defined(STM32F10X_MD) || defined(STM32F10X_CL)
|
||||||
#define SOFT_I2C_STM32F1_USED ///< 使用STM32F1芯片
|
#define SOFT_I2C_STM32F1_USED ///< 使用STM32F1芯片
|
||||||
#else
|
#else
|
||||||
#error "Please select the target chip model!"
|
#error "Please define GD32F30X_XX or STM32F10X_XX"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SOFT_I2C_GD32F3_USED)
|
#if defined(SOFT_I2C_GD32F3_USED)
|
||||||
|
@ -17,6 +17,15 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* 根据不同的芯片包含不同的文件 */
|
||||||
|
#if defined(GD32F30X_HD) || defined(GD32F30X_CL) || defined(GD32F30X_XD)
|
||||||
|
#define SOFT_I2C_GD32F3_USED ///< 使用GD32F3芯片
|
||||||
|
#elif defined(STM32F10X_HD) || defined(STM32F10X_MD) || defined(STM32F10X_CL)
|
||||||
|
#define SOFT_I2C_STM32F1_USED ///< 使用STM32F1芯片
|
||||||
|
#else
|
||||||
|
#error "Please define GD32F30X_XX or STM32F10X_XX"
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 软件模拟 I2C 通用宏定义
|
* @brief 软件模拟 I2C 通用宏定义
|
||||||
* @addtogroup SOFT_I2C_COMM_DEF
|
* @addtogroup SOFT_I2C_COMM_DEF
|
||||||
|
Binary file not shown.
Binary file not shown.
BIN
software_i2c/dsview/GD32F303RE_400K_O2.dsl
Normal file
BIN
software_i2c/dsview/GD32F303RE_400K_O2.dsl
Normal file
Binary file not shown.
BIN
software_i2c/dsview/GD32F303RE_400K_O3.dsl
Normal file
BIN
software_i2c/dsview/GD32F303RE_400K_O3.dsl
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
software_i2c/dsview/GD32F305ZE_400K_O2.dsl
Normal file
BIN
software_i2c/dsview/GD32F305ZE_400K_O2.dsl
Normal file
Binary file not shown.
BIN
software_i2c/dsview/GD32F305ZE_400K_O3.dsl
Normal file
BIN
software_i2c/dsview/GD32F305ZE_400K_O3.dsl
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
software_i2c/dsview/STM32F103C8_400K_O0.dsl
Normal file
BIN
software_i2c/dsview/STM32F103C8_400K_O0.dsl
Normal file
Binary file not shown.
BIN
software_i2c/dsview/STM32F103C8_400K_O1.dsl
Normal file
BIN
software_i2c/dsview/STM32F103C8_400K_O1.dsl
Normal file
Binary file not shown.
BIN
software_i2c/dsview/STM32F103C8_400K_O2.dsl
Normal file
BIN
software_i2c/dsview/STM32F103C8_400K_O2.dsl
Normal file
Binary file not shown.
BIN
software_i2c/dsview/STM32F103C8_400K_O3.dsl
Normal file
BIN
software_i2c/dsview/STM32F103C8_400K_O3.dsl
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user