野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 882|回复: 3

【求助】GD32模拟I2C问题

[复制链接]
发表于 2024-5-27 12:38:34 | 显示全部楼层 |阅读模式
  • 时序及其示波器显示波形如下所示,黄色为SDA。前面发送的数据没有任何问题,但是当接收数据的时候出现了如下所示问题。试过很多方法无果前来请教各位大佬!

  • 35baa9fdc9b7c56ac49d84291aed5430_720.jpg

  • image.png

  • GPIO设置如图所示,SCK和SDA均为推挽输出。

  • image.png -

  • 代码如下

  • 
    void i2c_start(void)
    {
        BK1080_SDA_DIR_OUT;
        BK1080_SDA_HIGH;
        bk1080_delay(1);
        BK1080_SCK_HIGH;
        bk1080_delay(1);
        BK1080_SDA_LOW;
        bk1080_delay(1);
        BK1080_SCK_LOW;
        bk1080_delay(1);
    }
    
    static void i2c_stop(void)
    {
        BK1080_SDA_DIR_OUT;
        BK1080_SDA_LOW;
        bk1080_delay(1);
        BK1080_SCK_LOW;
        bk1080_delay(1);
        BK1080_SCK_HIGH;
        bk1080_delay(1);
        BK1080_SDA_HIGH;
        bk1080_delay(1);
    }
    
    static void i2c_send(uint8_t data)
    {
        BK1080_SDA_DIR_OUT;
        BK1080_SCK_LOW;
        bk1080_delay(2);
        for (uint8_t i = 0; i < 8; i++)
        {
            if (data & 0x80)
                BK1080_SDA_HIGH;
            else
                BK1080_SDA_LOW;
            bk1080_delay(1);
            BK1080_SCK_HIGH;
            bk1080_delay(1);
            BK1080_SCK_LOW;
            bk1080_delay(2);
            data <<= 1;
        }
    }
    
    static uint8_t i2c_read(void)
    {
        uint8_t data = 0;
        BK1080_SDA_DIR_IN;
        BK1080_SCK_LOW;
        bk1080_delay(2);
        for (uint8_t i = 0; i < 8; i++)
        {
            data <<= 1;
            BK1080_SCK_HIGH;
            bk1080_delay(1);
            data |= BK1080_SDA_READ;
            bk1080_delay(1);
            BK1080_SCK_LOW;
            bk1080_delay(2);
        }
        return data;
    }
    
    static void i2c_send_ack(iic_ack_t ack)
    {
        BK1080_SDA_DIR_OUT;
        BK1080_SCK_LOW;
        bk1080_delay(1);
        if (ack)
            BK1080_SDA_HIGH;
        else
            BK1080_SDA_LOW;
        bk1080_delay(1);
        BK1080_SCK_HIGH;
        bk1080_delay(1);
        BK1080_SCK_LOW;
        bk1080_delay(2);
    }
    
    static uint8_t i2c_get_ack(void)
    {
        uint8_t ack;
        BK1080_SDA_DIR_IN;  
        BK1080_SCK_LOW;
        bk1080_delay(5);
        BK1080_SCK_HIGH;
        bk1080_delay(1);
        ack = BK1080_SDA_READ;
        bk1080_delay(1);
        BK1080_SCK_LOW;
        bk1080_delay(2);
        return ack;
    }
    
image.png
image.png
image.png
8da9b21689e30b936efe284fc84d1c0b.jpg
回复

使用道具 举报

 楼主| 发表于 2024-5-27 12:38:59 | 显示全部楼层
本帖最后由 Jamiexus19 于 2024-5-27 12:40 编辑

MCU为GD32F330CBT6
Device ID 为0x80
回复 支持 反对

使用道具 举报

发表于 2024-5-28 09:03:30 | 显示全部楼层
因为主机是IO口模拟IIC,所以发送没问题.但是可能从机不是IO模拟的IIC,从机发送IIC时因为没有上拉电阻所以驱动能力不够?
回复 支持 反对

使用道具 举报

发表于 2024-5-28 09:06:08 | 显示全部楼层
另外看起来你这个波形很奇怪请检查1.主从机是否共地2.主从机电压是否一直.可以考虑SCL与SDA线上分别串联一个10-100欧姆电阻来增加通讯稳定性.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-23 02:06 , Processed in 0.145605 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表