标题: stm32和AT24C02的硬件IIC通讯起始信号发送以后从机不应答? [打印本页]

作者: 凝_渊    时间: 2019-1-17 13:21
标题: stm32和AT24C02的硬件IIC通讯起始信号发送以后从机不应答?
stm32和AT24C02的硬件IIC通讯起始信号发送以后从机不应答

源码:
  1. #include "stm32f10x.h"
  2. #include "bsp_iic.h"
  3. #include "bsp_usart.h"
  4. #include "bsp_led.h"

  5. uint8_t temp_data[50];
  6. uint8_t temp_data_back[50];
  7. int IIC_Transmit_test(void);
  8. int main(void)
  9. {        
  10.         IIC_Init();
  11.         
  12.         USART_Config();
  13.         
  14.         LED_GPIO_Config();
  15.         printf("开始接收");
  16.         if(IIC_Transmit_test()== 1)
  17.         {
  18.                 LED_RED;
  19.         }
  20.         else
  21.         {
  22.                 LED_BLUE;
  23.         }
  24.         while(1)
  25.         {
  26.         }


  27. }
  28. //IIC数据传输检测
  29. int IIC_Transmit_test(void)
  30. {
  31.         uint8_t i=0;
  32.         
  33.         for(i=0;i<=10;i++)
  34.         {
  35.                 temp_data[i]=i;
  36.                 printf("%x  ",temp_data[i]);
  37.         }
  38.         
  39.         IIC_Write_page_fast(temp_data,0x00,10);
  40.         printf("写入成功");
  41.         IIC_Read_page(temp_data_back,0x00,10);
  42.         printf("读出的数据");
  43.         for(i=0;i<=10;i++)
  44.         {
  45.                 if(temp_data_back[i]==temp_data[i])
  46.                 {
  47.                         printf("%x  ",temp_data_back[i]);
  48.                 }
  49.                 else
  50.                 {
  51.                         printf("通讯失败");
  52.                         return 0;
  53.                 }
  54.         }
  55.         printf("读写测试成功");
  56.         return 1;
  57. }

复制代码

全部资料51hei下载地址:
MPU6050-1.7z (181.4 KB, 下载次数: 11)

作者: wushiye54    时间: 2019-1-18 11:38
STM32最好用模拟IIC,硬件IIC不怎么稳定
作者: whatsrong    时间: 2019-1-29 23:07
stm32的IIC最好是用IO口来模拟
作者: jinsheng7533967    时间: 2019-1-30 00:58
说的很有道理
作者: 笨笨兔    时间: 2019-1-30 08:37
STM32 硬件 IIC 有问题的,网上N多讨论,最好用IO来模拟;
之前的产品吃过这个亏,最后只能用模拟IIC来搞定。
作者: hotpet    时间: 2020-5-15 03:40
可以用片内Flash代替24c02.




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1