7487|16

79

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

有没有兄弟做过ST32读LM75的程序吗?QQ438948011 [复制链接]

                                 我做个好几天,第一遍能读第二遍就死在检测等待死了
此帖出自stm32/stm8论坛

最新回复

                                 我也碰到了这个问题 多次运行就不行了 开始几次 还行 也是死在   while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */   {   } 一直检测不到 不知道咋回事儿 这硬件。。。。  详情 回复 发表于 2010-8-11 15:14
点赞 关注
 

回复
举报

63

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
                                 用的是EK-ST32F开发板,用的是读2408示例程序
此帖出自stm32/stm8论坛
 
 

回复

76

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
                                 
此帖出自stm32/stm8论坛
 
 

回复

51

帖子

0

TA的资源

一粒金砂(初级)

4
 
                                 楼主不能仿真看程序死在哪了吗
此帖出自stm32/stm8论坛
 
 
 

回复

74

帖子

0

TA的资源

一粒金砂(初级)

5
 
                                 看你还挺高兴的啊
此帖出自stm32/stm8论坛
 
 
 

回复

69

帖子

0

TA的资源

一粒金砂(初级)

6
 
                                 检测等待?哪个检测等待,能不能说具体点呢,或者把程序拿出来看看
此帖出自stm32/stm8论坛
 
 
 

回复

83

帖子

0

TA的资源

一粒金砂(初级)

7
 
u32 I2C_EE_BufferRead(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead)
{
  /* Send START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
此帖出自stm32/stm8论坛
 
 
 

回复

74

帖子

0

TA的资源

一粒金砂(初级)

8
 
void I2C_EE_BufferRead(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead)
{  
  /* Send START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
  
  /* In the case of a single data transfer disable ACK before reading the data */
  if(NumByteToRead==1)
  {
    I2C_AcknowledgeConfig(I2C1, DISABLE);
  }
  
  /* Send EEPROM address for write */
  I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Transmitter);

  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
  
  /* Clear EV6 by setting again the PE bit */
  I2C_Cmd(I2C1, ENABLE);

  /* Send the EEPROM's internal address to write to */
  I2C_SendData(I2C1, ReadAddr);  

  /* Test on EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
  
  /* Send STRAT condition a second time */  
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
  
  /* Send EEPROM address for read */
  I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Receiver);
  
  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
  
  /* While there is data to be read */
  while(NumByteToRead)  
  {
    /* Test on EV7 and clear it */
    if(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))  
    {
      if(NumByteToRead == 2)
      {
        /* Disable Acknowledgement */
        I2C_AcknowledgeConfig(I2C1, DISABLE);
      }

      if(NumByteToRead == 1)
      {
        /* Send STOP Condition */
        I2C_GenerateSTOP(I2C1, ENABLE);
      }
      
      /* Read a byte from the EEPROM */
      *pBuffer = I2C_ReceiveData(I2C1);

      /* Point to the next location where the byte read will be saved */
      pBuffer++;
      
      /* Decrement the read bytes counter */
      NumByteToRead--;   
    }   
  }

  /* Enable Acknowledgement to be ready for another reception */
  I2C_AcknowledgeConfig(I2C1, ENABLE);
}
此帖出自stm32/stm8论坛
 
 
 

回复

78

帖子

0

TA的资源

一粒金砂(初级)

9
 
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
就这
此帖出自stm32/stm8论坛
 
 
 

回复

63

帖子

0

TA的资源

一粒金砂(初级)

10
 
后来改成这样了,但是还是只能读一次。LM75用GPIO模拟没有问题。
/*******************************************************************************
* Function Name  : I2C_EE_BufferRead
* Description    : Reads a block of data from the EEPROM.
* Input          : - pBuffer : pointer to the buffer that receives the data read
*                    from the EEPROM.
*                  - ReadAddr : EEPROM's internal address to read from.
*                  - NumByteToRead : number of bytes to read from the EEPROM.
* Output         : None
* Return         : None
*******************************************************************************/
u32 I2C_EE_BufferRead(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead)
{
  /* Send START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
          {TestI2C++;
          if(TestI2C==0xFF)
           {
             return 1;
           }
        }  
  TestI2C=0;
  /* In the case of a single data transfer disable ACK before reading the data */
  if(NumByteToRead==1)
  {
    I2C_AcknowledgeConfig(I2C1, DISABLE);
  }
  
  /* Send EEPROM address for write */
  I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Transmitter);

  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
          {TestI2C++;if(TestI2C==0xFF)
        {return 2;}}  
        TestI2C=0;
  /* Clear EV6 by setting again the PE bit */
  I2C_Cmd(I2C1, ENABLE);

  /* Send the EEPROM's internal address to write to */
  I2C_SendData(I2C1, ReadAddr);  

  /* Test on EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
          {TestI2C++;if(TestI2C==0xFF){return 3;}}  
         TestI2C=0;
  
  /* Send STRAT condition a second time */  
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
          {TestI2C++;if(TestI2C==0xFF){return 4;}}  
        TestI2C=0;
  
  /* Send EEPROM address for read */
  I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Receiver);
  
  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
          {TestI2C++;if(TestI2C==0xFF){return 5;}}  
        TestI2C=0;
  
  /* While there is data to be read */
  while(NumByteToRead)  
  {
    /* Test on EV7 and clear it */
   
   
      if(NumByteToRead == 2)
      {
        /* Disable Acknowledgement */
        I2C_AcknowledgeConfig(I2C1, DISABLE);
      }

      if(NumByteToRead == 1)
      {
        /* Send STOP Condition */
        I2C_GenerateSTOP(I2C1, ENABLE);
      }
       while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))
       {TestI2C++;if(TestI2C==0xFF){return 6;}}  
        TestI2C=0;
      /* Read a byte from the EEPROM */
      *pBuffer = I2C_ReceiveData(I2C1);

      /* Point to the next location where the byte read will be saved */
      pBuffer++;
      
      /* Decrement the read bytes counter */
      NumByteToRead--;   
      
  }

  /* Enable Acknowledgement to be ready for another reception */
  I2C_AcknowledgeConfig(I2C1, ENABLE);
  return 0;
}
此帖出自stm32/stm8论坛
 
 
 

回复

55

帖子

0

TA的资源

一粒金砂(初级)

11
 
                                 自己用IO口模拟的可以了。
此帖出自stm32/stm8论坛
 
 
 

回复

63

帖子

0

TA的资源

一粒金砂(初级)

12
 
                                 看来大公司的战略目的比信誉更重要。
此帖出自stm32/stm8论坛
 
 
 

回复

80

帖子

0

TA的资源

一粒金砂(初级)

13
 
                                 很明显,楼主的程序只能跑一次
此帖出自stm32/stm8论坛
 
 
 

回复

79

帖子

0

TA的资源

一粒金砂(初级)

14
 
                                 老问题了
此帖出自stm32/stm8论坛
 
 
 

回复

83

帖子

0

TA的资源

一粒金砂(初级)

15
 
                                 在调用I2C_EE_BufferRead,之前已经TestI2C=0;
此帖出自stm32/stm8论坛
 
 
 

回复

89

帖子

0

TA的资源

一粒金砂(初级)

16
 
我有些代码,可以读LM75,仅供参考(不保证能行):

#define LM75_Addr      0x90                // 7-bit address of LM75: left align to MSbit
#define LM75_Temp_Reg       0x00        // Temperature Register of LM75
#define LM75_Conf_Reg       0x01        // Configuration Register of LM75
#define LM75_Thyst_Reg      0x02        // Temperature Register of LM75
#define LM75_Tos_Reg        0x03        // Over-temp Shutdown threshold Register of LM75

#define Start_Bit        0x01
#define Address_Sent        0x02
#define BTF_Bit                0x04
#define Rx_Not_Empty                0x40

#define Ack_Failure                0x0400
#define Time_Out                0x4000


//-----------------------------------------------------------------
//   I2C_LM75(I2C1 of 1~2) initialization
//-----------------------------------------------------------------
void I2C_LM75_Init(void)
{
  I2C_InitTypeDef  I2C_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;

  // Enable I2C1 and GPIOB & AFEN(Alternate Function) clocks
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);

  // Reset I2C1 IP
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
  // Release reset signal of I2C1 IP
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);

  // Set PB6,7 as OD AF - I2C1_SCL, I2C1_SDA
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;        // standard: 100k, fast: 400k
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  // Set PB5 as PU in - TemperatureSensor_INT
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  // I2C1 configuration
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_ClockSpeed = 50000;                // 50k baud
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = 0x00;                // 7-bit own-address: right align to LSbit
  I2C_InitStructure.I2C_Ack = I2C_Ack_Disable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_Init(I2C1, &I2C_InitStructure);

  // Enable I2C1
  I2C_Cmd(I2C1, ENABLE);
}

//-----------------------------------------------------------------
//   Read Tos register of LM75
//-----------------------------------------------------------------
u16 I2C_LM75_Tos_Read(void)
{
  u16 u;
  u = 0xffff;                                        // init an invalid value

  // Generate START condition
  I2C_GenerateSTART(I2C1, ENABLE);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Start_Bit) )
    ;

  // Send 7bit Address
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Address_Sent) )
  {
    if( I2C_ReadRegister(I2C1, I2C_Register_SR1) & Ack_Failure )
    {
      I2C_GenerateSTOP(I2C1, ENABLE);
      return u;
    }
  }
  // Read SR2 to clear ADDR bit in SR1
  I2C_ReadRegister(I2C1, I2C_Register_SR2);

  // Send data: pointer (Tos_Reg)
  I2C_SendData(I2C1, LM75_Tos_Reg);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & BTF_Bit) )
  {
    if( I2C_ReadRegister(I2C1, I2C_Register_SR1) & (Time_Out | Ack_Failure) )
    {
      I2C_GenerateSTOP(I2C1, ENABLE);
      return u;
    }
  }

  // Generate STOP condition
  I2C_GenerateSTOP(I2C1, ENABLE);

  // Generate START condition
  I2C_GenerateSTART(I2C1, ENABLE);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Start_Bit) )
    ;

  // Send 7bit Address
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Receiver);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Address_Sent) )
  {
    if( I2C_ReadRegister(I2C1, I2C_Register_SR1) & Ack_Failure )
    {
      I2C_GenerateSTOP(I2C1, ENABLE);
      return u;
    }
  }
  // Read SR2 to clear ADDR bit in SR1
  I2C_ReadRegister(I2C1, I2C_Register_SR2);

  // Receive data: high byte (Tos_Reg) and ACK
  I2C_AcknowledgeConfig(I2C1, ENABLE);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Rx_Not_Empty) )
    ;
  u = I2C_ReceiveData(I2C1) << 8;

  // Receive data: low byte (Tos_Reg) and NAK
  I2C_AcknowledgeConfig(I2C1, DISABLE);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Rx_Not_Empty) )
    ;
  u |= I2C_ReceiveData(I2C1);

  I2C_GenerateSTOP(I2C1, ENABLE);

  // return correct result
  return u;
}

//-----------------------------------------------------------------
//   Read Temperature register of LM75
//-----------------------------------------------------------------
u16 I2C_LM75_Temp_Read(void)
{
  u16 u;
  u = 0xffff;                                        // init an invalid value

  // Generate START condition
  I2C_GenerateSTART(I2C1, ENABLE);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Start_Bit) )
    ;

  // Send 7bit Address
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Address_Sent) )
    ;
  // Read SR2 to clear ADDR bit in SR1
  I2C_ReadRegister(I2C1, I2C_Register_SR2);

  // Send data: pointer (Temp_Reg)
  I2C_SendData(I2C1, LM75_Temp_Reg);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & BTF_Bit) )
    ;

  // Generate STOP condition
  I2C_GenerateSTOP(I2C1, ENABLE);

  // Generate START condition
  I2C_GenerateSTART(I2C1, ENABLE);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Start_Bit) )
    ;

  // Send 7bit Address
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Receiver);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Address_Sent) )
    ;
  // Read SR2 to clear ADDR bit in SR1
  I2C_ReadRegister(I2C1, I2C_Register_SR2);

  // Receive data: high byte (Temp_Reg) and ACK
  I2C_AcknowledgeConfig(I2C1, ENABLE);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Rx_Not_Empty) )
    ;
  u = I2C_ReceiveData(I2C1) << 8;

  // Receive data: low byte (Temp_Reg) and NAK
  I2C_AcknowledgeConfig(I2C1, DISABLE);
  while( !(I2C_ReadRegister(I2C1, I2C_Register_SR1) & Rx_Not_Empty) )
    ;
  u |= I2C_ReceiveData(I2C1);

  I2C_GenerateSTOP(I2C1, ENABLE);

  // return correct result - Temp_Reg low 5 bits have no meaning
  return (u>>5);
}
此帖出自stm32/stm8论坛
 
 
 

回复

79

帖子

0

TA的资源

一粒金砂(初级)

17
 
我也碰到了这个问题 多次运行就不行了 开始几次 还行
也是死在
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
一直检测不到 不知道咋回事儿 这硬件。。。。
此帖出自stm32/stm8论坛
 
 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表