初级会员

- 积分
- 186
- 金钱
- 186
- 注册时间
- 2014-7-7
- 在线时间
- 0 小时
|

楼主 |
发表于 2015-3-29 10:08:56
|
显示全部楼层
回复【3楼】正点原子:
---------------------------------
我是这样设置的:
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PD2为SCL
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PC10为SDA,一开始都设置为开漏上拉输出
GPIO_Init(GPIOC,&GPIO_InitStructure);
SDA1;
SCL1;
宏定义是这样的
#define SCL1 GPIOD->BSRRL|=(1<<2)
#define SDA1 GPIOC->BSRRL|=(1<<10)
#define SCL0 GPIOD->BSRRH|=(1<<2)
#define SDA0 GPIOC->BSRRH|=(1<<10)
#define READ_SDA ((GPIOC->IDR&GPIO_Pin_10)!=0)?1:0
#define SDA_IN() {GPIOC->MODER|=GPIO_Mode_IN<<20;}
#define SDA_OUT() {GPIOC->MODER|=GPIO_Mode_OUT<<20;}
还是无法应答,模拟IIC里的程序是没有错的。 |
|