打印

stm32 硬件 i2c 问题

[复制链接]
18999|29
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
mochou|  楼主 | 2012-1-6 15:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我用硬件STM32的硬件i2c调试,一直有问题
ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT)
{
  uint32_t lastevent = 0;
  uint32_t flag1 = 0, flag2 = 0;
  ErrorStatus status = ERROR;
  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  assert_param(IS_I2C_EVENT(I2C_EVENT));
  /* Read the I2Cx status register */
  flag1 = I2Cx->SR1;
  flag2 = I2Cx->SR2;
  flag2 = flag2 << 16;
  /* Get the last event value from I2C status register */
  lastevent = (flag1 | flag2) & FLAG_Mask;
  /* Check whether the last event is equal to I2C_EVENT */
  if (lastevent == I2C_EVENT )
  {
    /* SUCCESS: last event is equal to I2C_EVENT */
    status = SUCCESS;
  }
  else
  {
    /* ERROR: last event is different from I2C_EVENT */
    status = ERROR;
  }
  /* Return status */
  return status;
}
状态一直为 status = ERROR;,所以程序一直停在
/* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); //等待START产生成功
请问该怎么解决,谢谢。
沙发
mochou|  楼主 | 2012-1-9 08:59 | 只看该作者
人呢,没有大侠们看到小弟的问题?

使用特权

评论回复
板凳
IJK| | 2012-1-9 11:19 | 只看该作者
STM32的硬件i2c,我也碰到过一些问题,后来问题通过一些方法避免了,感觉它的I2C状态机容易乱掉。
另外,从使用上有些地方需要注意,SCL、SDA引脚在初始化时会有毛刺,这2个IO的初始化顺序需要进行调整,否则毛刺会带来问题。

使用特权

评论回复
地板
mochou|  楼主 | 2012-1-9 13:30 | 只看该作者
3# IJK
谢谢这么哥们,可以把的I2C程序发我看下,mochou99@sina.cn

使用特权

评论回复
5
mochou|  楼主 | 2012-1-10 11:20 | 只看该作者
现在总是停在
/* Test on EV7 and clear it */
    if(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))  
大侠们指点下了。

使用特权

评论回复
6
w6850916| | 2012-6-27 13:20 | 只看该作者
请问楼主这个问题解决了吗?我现在也遇到这个问题不知道怎么解决。

使用特权

评论回复
7
lyncxy119| | 2012-6-28 21:54 | 只看该作者
我也遇到这个问题了,我用stm32的I2C读zlg7290键盘,一直卡在那里,不知道什么原因,大家都说st的库有问题,后来我就改用IO模拟I2C了,期待大神解决这个问题的方法

使用特权

评论回复
8
SecondLife| | 2012-6-29 10:53 | 只看该作者
我这两天刚做出来这个,原来也是这个问题,你看看管脚有没有用错,别的按例程上改应该就可以了;

使用特权

评论回复
9
lgp519| | 2012-6-29 10:56 | 只看该作者
有谁做出来的 联系我的qq:16545505

使用特权

评论回复
10
feng_710| | 2012-6-29 16:12 | 只看该作者
STM32的I2C确实是不太好用,我当时也是调了很久才调出来,不过我用的是查询方式做的

使用特权

评论回复
11
lgp519| | 2012-7-3 15:19 | 只看该作者
I2C我调出来了   
1  在STM32L151CBT6上,调不出来是由于芯片不行,换了一片就好了,nnd,其它功能好的,就硬件I2C坏的;
2 在另一款芯片STM32F103ZGT6上,程序停在了
    /* Test on I2C1 EV5 and clear it */
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

原因:是因为FSMC模块和I2C1模块共用了PB7引脚所以使得I2C1没有正常启动,而且即使你没有用到FSMC只是打开了FSMC的时钟也会影响I2C1的启动。解决办法是改用I2C2或者重定义I2C的时钟线和数据线到PB8、9引脚;或者关掉FSMC的时钟。

使用特权

评论回复
12
dsdslwf| | 2012-9-13 16:40 | 只看该作者
我也碰到I2C硬件问题,芯片型号是STM32F103RBT6 ,GH206, 不知道是哪一年生产的.
我用示波器测试过SDA和SCL信号线,SDA能输出完整的数据信号, SCL没有输出时钟信号.程序停在没有收到应答信号的地方.如果重新启动I2C就会进入I2C中断死循环.

使用特权

评论回复
13
dsdslwf| | 2012-9-13 16:40 | 只看该作者
我也碰到I2C硬件问题,芯片型号是STM32F103RBT6 ,GH206, 不知道是哪一年生产的.
我用示波器测试过SDA和SCL信号线,SDA能输出完整的数据信号, SCL没有输出时钟信号.程序停在没有收到应答信号的地方.如果重新启动I2C就会进入I2C中断死循环.

使用特权

评论回复
14
hitler617| | 2012-9-14 10:01 | 只看该作者
最近一直在做,在107上用中断 能够正常读写at24c02了。
start失败应该是总线忙,或者管脚配置不对,你再看看。
generate start之前要while(总线不忙),看这个while能不能过先

使用特权

评论回复
15
金融小数| | 2012-9-14 10:38 | 只看该作者
唉!好像STM32的I2C的问题不断啊!

使用特权

评论回复
16
清风致影| | 2012-9-14 12:02 | 只看该作者
直接上模拟呗

使用特权

评论回复
17
parallax| | 2013-1-8 16:09 | 只看该作者
楼主调出来了没有啊,我的是初始化完成之后,SCL SDA都拉低了,写数据时SCL有信号,SDA一直是低电平。

使用特权

评论回复
18
JasonWangFAE| | 2013-1-8 16:47 | 只看该作者
1.Use CPAL library when you went to use I2C in your application that provided by ST
2.Use interrupt and DMA .

使用特权

评论回复
19
杨爱林林| | 2013-1-9 10:29 | 只看该作者
I2C和spi调试都比较麻烦
要么折磨死人 要么一下就成功
之前调spi的时候,因为一个细节,没有erase,只能写,读不正确
像这样的细节问题 多遇到才好

使用特权

评论回复
20
parallax| | 2013-1-9 14:41 | 只看该作者
STM32F407的硬件I2C,现在的问题是将IO配置完成后SDA,SCL就拉低了,一开始就不正常了啊,配置的步骤ahi按照库文件I2C.C中的说明来配置的。
How to use this driver
  *          ===================================================================
  *          1. Enable peripheral clock using RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2Cx, ENABLE)
  *             function for I2C1, I2C2 or I2C3.
  *
  *          2. Enable SDA, SCL  and SMBA (when used) GPIO clocks using  
  *             RCC_AHBPeriphClockCmd() function.  
  *
  *          3. Peripherals alternate function:  
  *                 - Connect the pin to the desired peripherals' Alternate  
  *                   Function (AF) using GPIO_PinAFConfig() function
  *                 - Configure the desired pin in alternate function by:
  *                   GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
  *                 - Select the type, pull-up/pull-down and output speed via  
  *                   GPIO_PuPd, GPIO_OType and GPIO_Speed members
  *                 - Call GPIO_Init() function
  *                 Recommended configuration is Push-Pull, Pull-up, Open-Drain.
  *                 Add an external pull up if necessary (typically 4.7 KOhm).      
  *         
  *          4. Program the Mode, duty cycle , Own address, Ack, Speed and Acknowledged
  *             Address using the I2C_Init() function.
  *
  *          5. Optionally you can enable/configure the following parameters without
  *             re-initialization (i.e there is no need to call again I2C_Init() function):
  *              - Enable the acknowledge feature using I2C_AcknowledgeConfig() function
  *              - Enable the dual addressing mode using I2C_DualAddressCmd() function
  *              - Enable the general call using the I2C_GeneralCallCmd() function
  *              - Enable the clock stretching using I2C_StretchClockCmd() function
  *              - Enable the fast mode duty cycle using the I2C_FastModeDutyCycleConfig()
  *                function.
  *              - Configure the NACK position for Master Receiver mode in case of  
  *                2 bytes reception using the function I2C_NACKPositionConfig().   
  *              - Enable the PEC Calculation using I2C_CalculatePEC() function
  *              - For SMBus Mode:  
  *                   - Enable the Address Resolution Protocol (ARP) using I2C_ARPCmd() function
  *                   - Configure the SMBusAlert pin using I2C_SMBusAlertConfig() function
  *
  *          6. Enable the NVIC and the corresponding interrupt using the function  
  *             I2C_ITConfig() if you need to use interrupt mode.  
  *
  *          7. When using the DMA mode  
  *                   - Configure the DMA using DMA_Init() function
  *                   - Active the needed channel Request using I2C_DMACmd() or
  *                     I2C_DMALastTransferCmd() function.
  *              @note When using DMA mode, I2C interrupts may be used at the same time to
  *                    control the communication flow (Start/Stop/Ack... events and errors).
  *  
  *          8. Enable the I2C using the I2C_Cmd() function.
  *  
  *          9. Enable the DMA using the DMA_Cmd() function when using DMA mode in the  
  *             transfers.   


的第3条的最后一句话,Recommended configuration is Push-Pull, Pull-up, Open-Drain.这个地方到底应该怎么配置,又是Push-Pull,又是 Open-Drain?
我按照库文件的说明一项一项的来配置,还是只要是把IO初始化完后,SDA就拉低了

使用特权

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

本版积分规则

58

主题

1422

帖子

8

粉丝