【求助】CH32X035G8U6的硬件IIC問題

我初始化IIC以后再讀取傳感器設(shè)備的寄存器,但是代碼會在

I2C_GenerateSTART(?I2C1,?ENABLE?);

之后的

while(?!I2C_CheckEvent(?I2C1,?I2C_EVENT_MASTER_MODE_SELECT?)?);

這一句無限循環(huán),看起來開始信號并沒有發(fā)出去


這是完整代碼

????????GPIO_InitTypeDef?GPIO_InitStructure={0};
????????I2C_InitTypeDef?I2C_InitTSturcture={0};

????????RCC_APB2PeriphClockCmd(?RCC_APB2Periph_GPIOC,?ENABLE?);
????????RCC_APB1PeriphClockCmd(?RCC_APB1Periph_I2C1,?ENABLE?);
????????RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
????????GPIO_PinRemapConfig(GPIO_PartialRemap3_I2C1,?ENABLE);//C17-SCL?C16-SDA

????????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_17;//
????????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP;
????????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????????GPIO_Init(?GPIOC,?&GPIO_InitStructure?);

????????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_16;//
????????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP;
????????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????????GPIO_Init(?GPIOC,?&GPIO_InitStructure?);

????????I2C_InitTSturcture.I2C_ClockSpeed?=?bound;
????????I2C_InitTSturcture.I2C_Mode?=?I2C_Mode_I2C;
????????I2C_InitTSturcture.I2C_DutyCycle?=?I2C_DutyCycle_16_9;
????????I2C_InitTSturcture.I2C_OwnAddress1?=?address;
????????I2C_InitTSturcture.I2C_Ack?=?I2C_Ack_Enable;
????????I2C_InitTSturcture.I2C_AcknowledgedAddress?=?I2C_AcknowledgedAddress_7bit;
????????I2C_Init(?I2C1,?&I2C_InitTSturcture?);

????????I2C_Cmd(?I2C1,?ENABLE?);
????????I2C_AcknowledgeConfig(?I2C1,?ENABLE?);
	????????????while(?I2C_GetFlagStatus(?I2C1,?I2C_FLAG_BUSY?)?!=?RESET?);
	????????????I2C_GenerateSTART(?I2C1,?ENABLE?);//send?start

	????????????while(?!I2C_CheckEvent(?I2C1,?I2C_EVENT_MASTER_MODE_SELECT?)?);
	????????????I2C_Send7bitAddress(?I2C1,?0x18,?I2C_Direction_Transmitter?);

	????????????while(?!I2C_CheckEvent(?I2C1,?I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED?)?);
	????????????while(?!I2C_CheckEvent(?I2C1,?I2C_EVENT_MASTER_BYTE_TRANSMITTING?)?);
	????????????I2C_SendData(?I2C1,?0x0f);

	????????????while(?!I2C_CheckEvent(?I2C1,?I2C_EVENT_MASTER_BYTE_TRANSMITTED?)?);
	????????????I2C_GenerateSTART(I2C1,?ENABLE);

	????????????while(?!I2C_CheckEvent(?I2C1,?I2C_EVENT_MASTER_MODE_SELECT?)?);
	????????????I2C_Send7bitAddress(?I2C1,?0x18,?I2C_Direction_Receiver?);

	????????????while(!I2C_CheckEvent(I2C1,?I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
	????????????while(?I2C_GetFlagStatus(?I2C1,?I2C_FLAG_RXNE?)?==??RESET?)
	????????????I2C_AcknowledgeConfig(?I2C1,?DISABLE?);

	????????????printf("%x\r\n",I2C_ReceiveData(I2C1));

	????????????I2C_GenerateSTOP(?I2C1,?ENABLE?);


您好,可以先看一下芯片上的絲印,I2C功能不適用于批號倒數(shù)第五位為0的產(chǎn)品,在數(shù)據(jù)手冊有相關(guān)介紹,如下圖。若不支持,可以使用模擬IIC,具體可以看一下下帖鏈接。若是支持硬件IIC,可以檢查一下IIC引腳是否有接上拉,可以檢測一下IIC總線空閑時候的電平是否為高電平。后續(xù)若有問題,可以郵箱(lzs@wch.cn)溝通。

https://www.cnblogs.com/liaigu/p/17784027.html image.png


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频