问答

汇集网友智慧,解决技术难题

21ic问答首页 - GD32F1x0_Firmware_Library_v3.1.0 i2c demo有问题

GD32F1x0_Firmware_Library_v3.1.0 i2c demo有问题

tincal2022-03-28
一直卡在标红这行,请问有知道的么,谢谢

int main(void)
{
    int i;

    /* RCU config */
    rcu_config();
    /* GPIO config */
    gpio_config();
    /* I2C config */
    i2c_config();

    for(i=0; i<16; i++){
        i2c_transmitter=i+0x80;
    }

    /* wait until I2C bus is idle */
    while(i2c_flag_get(BOARD_I2C, I2C_FLAG_I2CBSY));
    /* send a start condition to I2C bus */
    i2c_start_on_bus(BOARD_I2C);
    /* wait until SBSEND bit is set */
    while(!i2c_flag_get(BOARD_I2C, I2C_FLAG_SBSEND));
    /* send slave address to I2C bus */
    i2c_master_addressing(BOARD_I2C, I2C_SLAVE_ADDRESS7, I2C_TRANSMITTER);
    /* wait until ADDSEND bit is set */
    while(!i2c_flag_get(BOARD_I2C, I2C_FLAG_ADDSEND));
    /* clear ADDSEND bit */
    i2c_flag_clear(BOARD_I2C, I2C_STAT0_ADDSEND);
    /* wait until the transmit data buffer is empty */
    while(!i2c_flag_get(BOARD_I2C, I2C_FLAG_TBE));

    for(i=0; i<16; i++){
        /* data transmission */
        i2c_data_transmit(BOARD_I2C, i2c_transmitter);
        /* wait until the TBE bit is set */
        while(!i2c_flag_get(BOARD_I2C, I2C_FLAG_TBE));
    }
    /* send a stop condition to I2C bus */
    i2c_stop_on_bus(BOARD_I2C);
    while(I2C_CTL0(BOARD_I2C)&0x0200);

    /* infinite loop */
    while(1){
    }
}
回答 +关注 3
702人浏览 0人回答问题 分享 举报
0 个回答

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