CH32V203G6U6 IIC通信

在G6U6封裝中,IIC引腳為PB6、PB7;需求驅(qū)動(dòng)AS5600磁編碼器;

IIC初始化代碼如下:

void?AS5600_Init(void)
{
????GPIO_InitTypeDef?GPIO_InitStructure={0};
????I2C_InitTypeDef?I2C_InitTSturcture={0};

????RCC_APB2PeriphClockCmd(?RCC_APB2Periph_GPIOB?,?ENABLE?);
????RCC_APB1PeriphClockCmd(?RCC_APB1Periph_I2C1,?ENABLE?);

????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_6;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP;//按手冊(cè)要求應(yīng)該是AF_OD,但是設(shè)置成AF_OD就一點(diǎn)輸出都沒(méi)有
????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????GPIO_Init(?GPIOB,?&GPIO_InitStructure?);

????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_7;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP;
????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????GPIO_Init(?GPIOB,?&GPIO_InitStructure?);

????I2C_InitTSturcture.I2C_ClockSpeed?=?100?*?1000;??
????I2C_InitTSturcture.I2C_Mode?=?I2C_Mode_I2C;
????I2C_InitTSturcture.I2C_DutyCycle?=?I2C_DutyCycle_16_9;
????I2C_InitTSturcture.I2C_OwnAddress1?=?0x00;
????I2C_InitTSturcture.I2C_Ack?=?I2C_Ack_Enable;
????I2C_InitTSturcture.I2C_AcknowledgedAddress?=?I2C_AcknowledgedAddress_7bit;
????I2C_Init(?I2C1,?&I2C_InitTSturcture?);

????I2C_Cmd(?I2C1,?ENABLE?);
}

但是使用邏輯分析儀并不能采集到完整的IIC信號(hào)波形;在V307和V203的示例程序中,IIC的使用均是PB8、PB9的重映射,而G6U6剛好沒(méi)有PB9引腳;

以下是邏輯分析儀100MHZ采集到的數(shù)據(jù),從RESET開(kāi)始:SDA信號(hào)并不完整

微信圖片_20240922152818.png

以下是獲取數(shù)據(jù)代碼:

uint16_t?AS5600_ReadRawAngle(void)?{
????uint16_t?Data;

????I2C_GenerateSTART(I2C1,?ENABLE);????//Start_Event
????AS5600_WaitEvent(I2C1,?I2C_EVENT_MASTER_MODE_SELECT);???//Event_5

????I2C_Send7bitAddress(I2C1,?AS5600_ADDR,?I2C_Direction_Transmitter);??//Fram_Head
????AS5600_WaitEvent(I2C1,?I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED);?//Event_9

????I2C_SendData(I2C1,?0x0C);???//addr
????AS5600_WaitEvent(I2C1,?I2C_EVENT_MASTER_BYTE_TRANSMITTED);??//Event_6

????I2C_GenerateSTART(I2C1,?ENABLE);????//ReStart
????AS5600_WaitEvent(I2C1,?I2C_EVENT_MASTER_MODE_SELECT);???//Event_5

????I2C_Send7bitAddress(I2C1,?AS5600_ADDR,?I2C_Direction_Receiver);?//Fram_Head
????AS5600_WaitEvent(I2C1,?I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED);????//Event_6

????AS5600_WaitEvent(I2C1,?I2C_EVENT_MASTER_BYTE_RECEIVED);?//Event_7
????Data?=?I2C_ReceiveData(I2C1);???//Read_Data
????Data?=?Data?<<?8;

????I2C_AcknowledgeConfig(I2C1,?ENABLE);????//Non_ACK
????I2C_GenerateSTOP(I2C1,?ENABLE);?//Stop_Event

????Data?|=?I2C_ReceiveData(I2C1);???//Read_Data

????I2C_AcknowledgeConfig(I2C1,?ENABLE);????//ACK

????return?Data;


查閱了更多的資料發(fā)現(xiàn),復(fù)用開(kāi)漏輸出無(wú)法輸出高電平,IIC總線必須上拉才可以正常使用


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

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