-
GD32 F4硬件I2C总是锁死
1.问题描述买了一个磁力计模块,用杜邦线连接到427start开发板,参考网上各种例程一直失败,要么是ADSEND不置1,要么是I2C总线一直忙,反复置位或者上电重启能读到一次,今天尝试了参考官方EEPROM的延时检测程序,还是没办法实现,求解求解!!2.代码代码1:未加延时检测代码while(i2c_flag_get(I2C1,I2C_FLAG_I2CBSY));printf("I2Cbusisidle\r\n");i2c_start_on_bus(I2C1);while(!i2c_flag_get(I2C1,I2C_FLAG_SBSEND));printf("SBSENDbitisset\r\n");i2c_master_addressing(I2C1,QMC5883L_DEFAULT_ADDRESS,I2C_RECEIVER);while(!i2c_flag_get(I2C1,I2C_FLAG_ADDSEND));printf("ADDSENDbitisset\r\n");i2c_flag_clear(I2C1,I2C_FLAG_ADDSEND);i2c_ack_config(I2C1,I2C_ACK_DISABLE);i2c_stop_on_bus(I2C1);while(!i2c_flag_get(I2C1,I2C_FLAG_RBNE));printf("I2C_FLAG_RBNEbitisset\r\n");chipID=i2c_data_receive(I2C1);printf("0x%u\r\n",chipID);++++++++++++++++++++++++++++++++++++++++++++++++代码2延时检测/*!\filemain.c\briefGPIOrunningleddemo\version2022-04-26,V2.0.0,demoforGD32F4xx*//*Copyright(c)2022,GigaDeviceSemiconductorInc.Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,arepermittedprovidedthatthefollowingconditionsaremet:1.Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistofconditionsandthefollowingdisclaimer.2.Redistributionsinbinaryformmustreproducetheabovecopyrightnotice,thislistofconditionsandthefollowingdisclaimerinthedocumentationand/orothermaterialsprovidedwiththedistribution.3.Neitherthenameofthecopyrightholdernorthenamesofitscontributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftwarewithoutspecificpriorwrittenpermission.THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTO
2022-10-22 9 -
GD32E503硬件I2C问题
求大佬们帮忙看看刚开始搞编程,最近在学习GD32E503-Start的开发板,按照官方提供的固件库使用指南操作在使用硬件I2C的时候发现ADDSEND位一直不置1,导致程序一直卡在while(!i2c_flag_get(i2c_periph,I2C_FLAG_ADDSEND));检查硬件连接也没啥问题,把程序下进去之后,疯狂按复位,发现有那么几次ADDSEND被置1了,真的搞不清楚什么情况,求各位帮忙看看,代码是按照官方提供的例程写的,使用的是I2C1,PB10,PB11引脚voidlmp_reg_write(uint32_ti2c_periph,uint32_tlmp_reg,uint8_tdatatransmit){while(i2c_flag_get(i2c_periph,I2C_FLAG_I2CBSY));i2c_start_on_bus(i2c_periph);while(!i2c_flag_get(i2c_periph,I2C_FLAG_SBSEND));i2c_master_addressing(i2c_periph,LMP_ADDR_WRITE,I2C_TRANSMITTER);while(!i2c_flag_get(i2c_periph,I2C_FLAG_ADDSEND));i2c_flag_clear(i2c_periph,I2C_FLAG_ADDSEND);while(!i2c_flag_get(i2c_periph,I2C_FLAG_TBE));i2c_data_transmit(i2c_periph,lmp_reg);while(!i2c_flag_get(i2c_periph,I2C_FLAG_TBE));i2c_data_transmit(i2c_periph,datatransmit);while(!i2c_flag_get(i2c_periph,I2C_FLAG_BTC));i2c_stop_on_bus(i2c_periph);while(I2C_CTL0(i2c_periph)&0x0200);}供电我是直接用usb线到电脑上,连的gd-link那个usb口,也方便烧录。
2021-10-09 4