STM32 双向IO口的问题 _STM32_快来啊,呜呜

2020-01-01 17:45发布

我的STM32需要使用双向的IO口,电路使用的是4.7k外部上拉,由于使用的是开发板,没法在芯片引脚处加,就在外接芯片处加入了上拉,这个区别大吗?

软件方面,就是设为OD输出,读输入之前写高电平,如下:GPIOE->ODR = 0xffff;  RWord1 = GPIOE->IDR;
问题是,我每次读到的数据都是高电平,我对外部写高电平后,不是立即读,中间有别的操作

这个搞了好几天,也没有什么结果,请高手给看看吧
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
19条回答
yisea123
2020-01-02 19:44
大致结构如下:

#define LCD_DATA (GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10| GPIO_Pin_11 | GPIO_Pin_12| GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15)

void __LCD19264_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  //端口默认为输出
  GPIO_InitStructure.GPIO_Pin =LCD_DATA;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

}

u8 __LCD19264_ReadData(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  //切换为输入口
  GPIO_InitStructure.GPIO_Pin =LCD_DATA;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  读取并处理;

  //还原成输出口
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  返回读取的值;
}

一周热门 更多>