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:
ArthurCai 2024-01-30 21:54:07 +08:00
parent 3d500401a9
commit 3921acd5c7
19 changed files with 12 additions and 2 deletions

View File

@ -327,6 +327,7 @@ static soft_i2c_err_t soft_i2c_read_byte(P_SOFT_I2C_T p_i2c, uint8_t *p_data) {
#endif
soft_i2c_write_gpio(&p_i2c->sda, SOFT_I2C_LEVEL_HIGH); // 开启线与
for (loopCnt = 0; loopCnt < 8; loopCnt++) {
soft_i2c_delay_us();
*p_data <<= 1;
soft_i2c_write_gpio(&p_i2c->scl, SOFT_I2C_LEVEL_HIGH); // 拉起SCL
#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); // 读取数据
soft_i2c_delay_800ns();
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_delay_800ns();
return SOFT_I2C_ERR_OK;
}

View File

@ -21,7 +21,7 @@
#elif defined(STM32F10X_HD) || defined(STM32F10X_MD) || defined(STM32F10X_CL)
#define SOFT_I2C_STM32F1_USED ///< 使用STM32F1芯片
#else
#error "Please select the target chip model!"
#error "Please define GD32F30X_XX or STM32F10X_XX"
#endif
#if defined(SOFT_I2C_GD32F3_USED)

View File

@ -17,6 +17,15 @@
#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
* @addtogroup SOFT_I2C_COMM_DEF

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.