野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9735|回复: 5

ov7725 sccb的sda引脚配置问题

[复制链接]
发表于 2016-11-5 22:14:20 | 显示全部楼层 |阅读模式
//1处
macOV7725_SIO_D_SCK_APBxClock_FUN ( macOV7725_SIO_D_GPIO_CLK, ENABLE );
GPIO_InitStructure.GPIO_Pin =  macOV7725_SIO_D_GPIO_PIN ;
GPIO_Init(macOV7725_SIO_D_GPIO_PORT, &GPIO_InitStructure);

//2处
#define SDA_H         GPIO_SetBits(macOV7725_SIO_D_GPIO_PORT , macOV7725_SIO_D_GPIO_PIN)
#define SDA_L         GPIO_ResetBits(macOV7725_SIO_D_GPIO_PORT , macOV7725_SIO_D_GPIO_PIN)

//3处
#define SCL_read      GPIO_ReadInputDataBit(macOV7725_SIO_C_GPIO_PORT , macOV7725_SIO_C_GPIO_PIN)
#define SDA_read      GPIO_ReadInputDataBit(macOV7725_SIO_D_GPIO_PORT , macOV7725_SIO_D_GPIO_PIN)


1处这样配置引脚后,引脚默认是什么状态(输出、输入、推挽、开漏)?

2处这样配置就能使引脚输出为高了吗,加入引脚原来默认为下拉输入呢?

3处这样配置就能读出引脚的状态并且设置为输入了吗,如果引脚为(上拉、下拉)输出模式,读取的引脚状态是正确的吗?

回复

使用道具 举报

发表于 2016-11-6 14:53:14 | 显示全部楼层
1.看你前面GPIO_InitStructure结构体的模式配置
2.可以,原来是什么模式不影响
3.可以,原来是什么模式不影响
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-11-7 16:52:18 | 显示全部楼层
1处,我看了一下库函数,在这个函数里:
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
{
  uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;
  uint32_t tmpreg = 0x00, pinmask = 0x00;
  /* Check the parameters */
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
  assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));  
  
/*---------------------------- GPIO Mode Configuration -----------------------*/
  currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F);
  if ((((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x10)) != 0x00)
  {
    /* Check the parameters */
    assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
    /* Output mode */
    currentmode |= (uint32_t)GPIO_InitStruct->GPIO_Speed;
  }
/*---------------------------- GPIO CRL Configuration ------------------------*/
  /* Configure the eight low port pins */
  if (((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x00FF)) != 0x00)
  {
    tmpreg = GPIOx->CRL;
    for (pinpos = 0x00; pinpos < 0x08; pinpos++)
    {
      pos = ((uint32_t)0x01) << pinpos;
      /* Get the port pins position */
      currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
      if (currentpin == pos)
      {
        pos = pinpos << 2;
        /* Clear the corresponding low control register bits */
        pinmask = ((uint32_t)0x0F) << pos;
        tmpreg &= ~pinmask;
        /* Write the mode configuration in the corresponding bits */
        tmpreg |= (currentmode << pos);
        /* Reset the corresponding ODR bit */
        if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
        {
          GPIOx->BRR = (((uint32_t)0x01) << pinpos);
        }
        else
        {
          /* Set the corresponding ODR bit */
          if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
          {
            GPIOx->BSRR = (((uint32_t)0x01) << pinpos);
          }
        }
      }
    }
    GPIOx->CRL = tmpreg;
  }
/*---------------------------- GPIO CRH Configuration ------------------------*/
  /* Configure the eight high port pins */
  if (GPIO_InitStruct->GPIO_Pin > 0x00FF)
  {
    tmpreg = GPIOx->CRH;
    for (pinpos = 0x00; pinpos < 0x08; pinpos++)
    {
      pos = (((uint32_t)0x01) << (pinpos + 0x08));
      /* Get the port pins position */
      currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);
      if (currentpin == pos)
      {
        pos = pinpos << 2;
        /* Clear the corresponding high control register bits */
        pinmask = ((uint32_t)0x0F) << pos;
        tmpreg &= ~pinmask;
        /* Write the mode configuration in the corresponding bits */
        tmpreg |= (currentmode << pos);
        /* Reset the corresponding ODR bit */
        if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
        {
          GPIOx->BRR = (((uint32_t)0x01) << (pinpos + 0x08));
        }
        /* Set the corresponding ODR bit */
        if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
        {
          GPIOx->BSRR = (((uint32_t)0x01) << (pinpos + 0x08));
        }
      }
    }
    GPIOx->CRH = tmpreg;
  }
}

void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
{
  /* Reset GPIO init structure parameters values */
  GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
  GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;
}
如果没赋值的话,tmpreg就应该为0,最后 GPIOx->CRH = tmpreg;不就是模拟输入了吗,为什么引脚默认为浮空状态呢?我错哪里呢?还是说跟库函数里这个函数GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)有关呢?能解释一下吗
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-11-7 16:56:33 | 显示全部楼层
1处我就结构体里就只赋值了GPIO_InitStructure.GPIO_Pin =  macOV7725_SIO_D_GPIO_PIN ;这一个成员变量,其他的都没赋值
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-11-7 16:59:42 | 显示全部楼层
还想问的是2处的 GPIO_SetBits有没有改变引脚的输入输出模式。3处也是一样的问题
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-11-7 17:00:07 | 显示全部楼层
static int SCCB_Start(void)
{
        SDA_H;
        SCL_H;
        SCCB_delay();
        if(!SDA_read)
        return DISABLE;        /* SDA线为低电平则总线忙,退出 */
        SDA_L;
        SCCB_delay();
        if(SDA_read)
        return DISABLE;        /* SDA线为高电平则总线出错,退出 */
        SDA_L;
        SCCB_delay();
        return ENABLE;
}
既然SDA为浮空输入了,SDA_H这样能拉高吗,你们为什么要这样写,不用改变SDA为输出状态吗? 浮空输入的话SDA_L为什么能把你们摄像头的引脚拉低,在输入的情况下,用GPIO_SetBits(),是改变了图中4处的地方,让那个开光闭上了,所以能输出高电平吗
_`5N63~142FQ%A$66)Q[~AH.png
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-5-1 18:18 , Processed in 0.064258 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表