|
发表于 2023-1-10 15:02:57
|
显示全部楼层
另外补充一下 IO的初始化, I2C从模式,用的是 P3.3 /P3.2这两个脚,这两个IO口,我用的是芯片默认值 ,没有额外初始化,是否有问题
void IO_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin = GPIO_Pin_All;
GPIO_InitStructure.Mode = GPIO_HighZ;
GPIO_Inilize(GPIO_P0, &GPIO_InitStructure);
GPIO_Inilize(GPIO_P1, &GPIO_InitStructure);
GPIO_Inilize(GPIO_P2, &GPIO_InitStructure);
GPIO_Inilize(GPIO_P4, &GPIO_InitStructure);
GPIO_Inilize(GPIO_P5, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_Pin_2 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P0, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_Pin_1 | GPIO_Pin_7;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P1, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_Pin_1 | GPIO_Pin_3 | GPIO_Pin_5;;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P2, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_Pin_4 | GPIO_Pin_2 ;
GPIO_InitStructure.Mode = GPIO_PullUp;
GPIO_Inilize(GPIO_P2, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_Pin_4;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P3, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_Pin_3 | GPIO_Pin_7;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P4, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P5, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_Pin_3 | GPIO_Pin_2; //Ö¸¶¨Òª³õʼ»¯µÄIO, GPIO_Pin_0 ~ GPIO_Pin_7, »ò²Ù×÷
GPIO_InitStructure.Mode = GPIO_PullUp; //Ö¸¶¨IOµÄÊäÈë»òÊä³ö·½Ê½,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
GPIO_Inilize(GPIO_P4, &GPIO_InitStructure); //³õʼ»¯
//GPIO_InitStructure.Pin = GPIO_Pin_3 | GPIO_Pin_2; //Ö¸¶¨Òª³õʼ»¯µÄIO, GPIO_Pin_0 ~ GPIO_Pin_7, »ò²Ù×÷
//GPIO_InitStructure.Mode = GPIO_HighZ; //Ö¸¶¨IOµÄÊäÈë»òÊä³ö·½Ê½,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
//GPIO_Inilize(GPIO_P3, &GPIO_InitStructure); //³õʼ»¯
} |
|