打印
[STM32F0]

stm32f051r8t6 ------I2C库函数 疑惑

[复制链接]
1629|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lzf1738|  楼主 | 2015-2-13 15:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
小弟初次用stm32开发,使用I2C库函数 ,发现在初始化I2C完后, 用示波器 量测PB8 PB9  始终为低电平,并不为高。   请问 问题出在哪呢。
void GPIO_Configuration(void)
{
       
        GPIO_InitTypeDef GPIO_InitStruct;

        /*--HSI 8MHZ--*/
        RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);  
       
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);  

        /*--ʹÄÜI2CʱÖÓ--*/
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);

        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;
        GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3;
        GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
        GPIO_Init(GPIOB , &GPIO_InitStruct);

        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
        GPIO_Init(GPIOB , &GPIO_InitStruct);

        GPIO_PinAFConfig(GPIOB,GPIO_PinSource8,GPIO_AF_1);
        GPIO_PinAFConfig(GPIOB,GPIO_PinSource9,GPIO_AF_1);
               
}


void I2C_Configuration(void)
{

        I2C_InitTypeDef         I2C_InitStruct;
        I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
        I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
        I2C_InitStruct.I2C_DigitalFilter =  0x00;
        I2C_InitStruct.I2C_OwnAddress1 = 0x00;
        I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
        I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
        I2C_InitStruct.I2C_Timing = 0x00210507;

        I2C_Cmd(I2C1 , ENABLE);

        I2C_Init(I2C1 , &I2C_InitStruct);
       
}
沙发
zyj9490| | 2015-2-13 15:34 | 只看该作者
外部有没有上拉电阻,明显没有配置成上拉电阻的条件啊。

使用特权

评论回复
板凳
zyj9490| | 2015-2-13 15:37 | 只看该作者
还有一个PULL的选项。可以在内部配置的。

使用特权

评论回复
地板
lzf1738|  楼主 | 2015-2-13 15:59 | 只看该作者
外部有上拉,
也尝试  写成如下
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

结果SCL SDA  还是低。 电平始终为低。

使用特权

评论回复
5
lzf1738|  楼主 | 2015-2-13 16:00 | 只看该作者
zyj9490 发表于 2015-2-13 15:34
外部有没有上拉电阻,明显没有配置成上拉电阻的条件啊。

外部有上拉
也尝试配成推挽   
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

SDA SCL  始终为低电平

使用特权

评论回复
6
lzf1738|  楼主 | 2015-2-13 16:01 | 只看该作者
zyj9490 发表于 2015-2-13 15:34
外部有没有上拉电阻,明显没有配置成上拉电阻的条件啊。

外部有上拉
也尝试配成推挽   
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

SDA SCL  始终为低电平

使用特权

评论回复
7
lzf1738|  楼主 | 2015-2-13 16:02 | 只看该作者
zyj9490 发表于 2015-2-13 15:37
还有一个PULL的选项。可以在内部配置的。

小弟 没明白 请详细指点  这个是配成什么的

使用特权

评论回复
8
zyj9490| | 2015-2-13 18:08 | 只看该作者
lzf1738 发表于 2015-2-13 16:01
外部有上拉
也尝试配成推挽   
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

i2的端口只能配成开漏,OD,才

使用特权

评论回复
9
zyj9490| | 2015-2-13 18:21 | 只看该作者
lzf1738 发表于 2015-2-13 16:02
小弟 没明白 请详细指点  这个是配成什么的

typedef struct
{
  uint32_t Pin;       /*!< Specifies the GPIO pins to be configured.
                           This parameter can be any value of @ref GPIO_pins */

  uint32_t Mode;      /*!< Specifies the operating mode for the selected pins.
                           This parameter can be a value of @ref GPIO_mode */

  uint32_t Pull;      /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
                           This parameter can be a value of @ref GPIO_pull */

  uint32_t Speed;     /*!< Specifies the speed for the selected pins.
                           This parameter can be a value of @ref GPIO_speed */

  uint32_t Alternate;  /*!< Peripheral to be connected to the selected pins
                            This parameter can be a value of @ref GPIOEx_Alternate_function_selection */
}GPIO_InitTypeDef;

使用特权

评论回复
10
zyj9490| | 2015-2-13 18:26 | 只看该作者
/*******************************************************************************
* Function Name  : GPIO_PinRemapConfig
* Description    : Changes the mapping of the specified pin.
* Input          : - GPIO_Remap: selects the pin to remap.
*                    This parameter can be one of the following values:
*                       - GPIO_Remap_SPI1
*                       - GPIO_Remap_I2C1
*                       - GPIO_Remap_USART1
*                       - GPIO_Remap_USART2
*                       - GPIO_PartialRemap_USART3
*                       - GPIO_FullRemap_USART3
*                       - GPIO_PartialRemap_TIM1
*                       - GPIO_FullRemap_TIM1
*                       - GPIO_PartialRemap1_TIM2
*                       - GPIO_PartialRemap2_TIM2
*                       - GPIO_FullRemap_TIM2
*                       - GPIO_PartialRemap_TIM3
*                       - GPIO_FullRemap_TIM3
*                       - GPIO_Remap_TIM4
*                       - GPIO_Remap1_CAN
*                       - GPIO_Remap2_CAN
*                       - GPIO_Remap_PD01
*                       - GPIO_Remap_TIM5CH4_LSI
*                       - GPIO_Remap_ADC1_ETRGINJ
*                       - GPIO_Remap_ADC1_ETRGREG
*                       - GPIO_Remap_ADC2_ETRGINJ
*                       - GPIO_Remap_ADC2_ETRGREG
*                       - GPIO_Remap_SWJ_NoJTRST
*                       - GPIO_Remap_SWJ_JTAGDisable
*                       - GPIO_Remap_SWJ_Disable
*                  - NewState: new state of the port pin remapping.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None

使用特权

评论回复
11
lzf1738|  楼主 | 2015-2-13 22:39 | 只看该作者
zyj9490 发表于 2015-2-13 18:26
/*******************************************************************************
* Function Name  :  ...

GPIO_PinRemapConfig 还需要重映射下端口吗?

我参考青风的driver 里面似乎没有使用这

一般调GPIO_PinAFConfig(GPIOB,GPIO_PinSource8,GPIO_AF_1); 这个AF复用.应该不就可以了?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

13

帖子

1

粉丝