IIC通信问题



  • 关于iic通信,iic读函数,读出来的数就是从机地址,大家帮忙解答一下,谢谢

    system_set_port_mux(GPIO_PORT_A, GPIO_BIT_6, PORTA6_FUNC_I2C1_CLK);//PA6		IIC时钟->SCL/SI
    				system_set_port_mux(GPIO_PORT_A, GPIO_BIT_7, PORTA7_FUNC_I2C1_DAT);//PA7 		IIC数据->SDA/CS
    				
    				system_set_port_pull( (GPIO_PA6|GPIO_PA7),false);                   //PA6,PA7设为上拉
    

    // gpio_set_dir(GPIO_PORT_A, GPIO_BIT_7,GPIO_DIR_OUT); //输出模式
    iic_init(IIC_CHANNEL_0,1000,TMP102_DEV_ADDR); //通道0 速率400k,3011地址0
    co_printf("ARRIVE1\r\n");
    uint8_t chipID = 0x00;
    // icc_write_byte(IIC_CHANNEL_0,TMP102_DEV_ADDR,0x40,&chipID);
    if (iic_read_byte(IIC_CHANNEL_0,TMP102_DEV_ADDR,0x01,&chipID)) // CHIP_ID = 0xE7
    co_printf("CHIP ID:0x%2x\r\n",chipID);
    else
    co_printf("I2C Error\r\n");



  • 逻辑分析仪抓包看一下
    uint8_t AT24C02_ADDR = (0xA0);
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_6, PORTD6_FUNC_I2C1_CLK);//Pc6
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_7, PORTD7_FUNC_I2C1_DAT);//Pc7
    system_set_port_pull( (GPIO_PD6|GPIO_PD7), false);
    //IIC1, 1M hz. slave addr: 0xA0
    iic_init(IIC_CHANNEL_1,1000,AT24C02_ADDR);

    iic_write_byte(IIC_CHANNEL_1,AT24C02_ADDR,0x00,0x35);
    co_delay_100us(50);
    iic_write_byte(IIC_CHANNEL_1,AT24C02_ADDR,0x01,0x34);
    co_delay_100us(50);


  • @mars 我是初学,抓包我不太懂 ,用您的代码第二个write的while语句会陷入死循环0_1689130701277_121.png



  • 通讯地址确认一下 有没有问题



  • 你这个是没有初始化引脚,我也遇到过