標(biāo)題: stm32和AT24C02的硬件IIC通訊起始信號發(fā)送以后從機(jī)不應(yīng)答? [打印本頁]

作者: 凝_淵    時間: 2019-1-17 13:21
標(biāo)題: stm32和AT24C02的硬件IIC通訊起始信號發(fā)送以后從機(jī)不應(yīng)答?
stm32和AT24C02的硬件IIC通訊起始信號發(fā)送以后從機(jī)不應(yīng)答

源碼:
  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數(shù)據(jù)傳輸檢測
  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("讀出的數(shù)據(jù)");
  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. }

復(fù)制代碼

全部資料51hei下載地址:
MPU6050-1.7z (181.4 KB, 下載次數(shù): 11)

作者: wushiye54    時間: 2019-1-18 11:38
STM32最好用模擬IIC,硬件IIC不怎么穩(wěn)定
作者: whatsrong    時間: 2019-1-29 23:07
stm32的IIC最好是用IO口來模擬
作者: jinsheng7533967    時間: 2019-1-30 00:58
說的很有道理
作者: 笨笨兔    時間: 2019-1-30 08:37
STM32 硬件 IIC 有問題的,網(wǎng)上N多討論,最好用IO來模擬;
之前的產(chǎn)品吃過這個虧,最后只能用模擬IIC來搞定。
作者: hotpet    時間: 2020-5-15 03:40
可以用片內(nèi)Flash代替24c02.




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1