[技术问答] 76e003 P1.3 P1.4开漏输出上升沿缓慢

[复制链接]
1576|10
 楼主| hcf83098 发表于 2019-8-22 17:26 | 显示全部楼层 |阅读模式
请教各位大师,我用003  P1.3 P1.4 开漏输出做模拟I2C,上拉电阻4.7K(试过1K有改善,但不能彻底解决),外面只挂了个PCF8563,4us的高电平由于上升沿不够陡峭,变成了尖顶,用推挽输出可以很快。请知道的告诉一声,感激不尽!
tianxj01 发表于 2019-8-22 18:33 | 显示全部楼层
上升沿慢很正常,开漏如果负载容性比较大,或者哪怕走线走的长,对VCC、GND分布电容大点,上升沿就不会陡峭,你只是挂了一个IIC设备,测试过,在IIC线布线合适,长度100mm以内,标准的3.3K上拉就完全可以实现400KHz的IIC最高频率,这时候时钟才2.5uS呢,时钟的样子是一个上升沿稍慢的,顶部变成尖顶但是满幅度,由于标准硬件IIC是在上升沿和下降沿的一段时间,而尖顶的折合到门槛电压由至少1/2时钟宽度的有效时间,因此该样子时钟通讯完全正常。
你是软件模拟IIC,则可能时序上面处理不合理,会导致IIC数据处理容错性比较差。
到1K都改善不多,完全说明你的软IIC处理时序有问题。
注意IIC信号采集是在SCL上下沿之间采集SDA数据。如果是输出,则SDA数据的准备,必须在时钟低电平的时间的一半时刻完成。
wahahaheihei 发表于 2019-8-22 21:01 | 显示全部楼层
赶紧换了吧,用ML51或者MS51
wahahaheihei 发表于 2019-8-22 21:01 | 显示全部楼层
975135d5e922a9b321.png
MS51或者ML51被官方的PIN配置软件支持。
598330983 发表于 2019-8-24 10:21 | 显示全部楼层
你要算算实际上应该多少。
643757107 发表于 2019-8-24 10:24 | 显示全部楼层
这个要这么快是干啥的
xuanhuanzi 发表于 2019-8-24 10:37 | 显示全部楼层
003好像是有I2C的吧
21mengnan 发表于 2019-8-25 21:45 | 显示全部楼层
直接试试官方的
21mengnan 发表于 2019-8-25 21:45 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/29/2017
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 I2C master mode demo code, the Slave address = 0xA4
  14. //
  15. //   ____________            _____________
  16. //  |            |   SDA    |             |
  17. //  |            |<-------->|             |
  18. //  |            |          |             |
  19. //  |N76E003(M) |          | N76E003(S) |
  20. //  |(I2C_Master)|          | (I2C_Slave) |
  21. //  |            |   SCL    |             |
  22. //  |            |--------->|             |
  23. //  |____________|          |_____________|
  24. //
  25. //  The protocol of I2C is same the "24LC64"
  26. //***********************************************************************************************************


  27. #include "N76E003.h"
  28. #include "Common.h"
  29. #include "Delay.h"
  30. #include "SFR_Macro.h"
  31. #include "Function_define.h"

  32. #define I2C_CLOCK               13
  33. #define EEPROM_SLA              0xA4
  34. #define EEPROM_WR               0
  35. #define EEPROM_RD               1
  36. #define ERROR_CODE              0x78
  37. #define PAGE_SIZE               32

  38. //========================================================================================================
  39. void Init_I2C(void)
  40. {
  41. //    /* Set I2C clock rate */
  42.     I2CLK = I2C_CLOCK;

  43.     /* Enable I2C */
  44.     set_I2CEN;                                   
  45. }
  46. //========================================================================================================
  47. void I2C_Error(void)
  48. {
  49. //    P3 = I2STAT;
  50. //    P3 = ERROR_CODE;
  51.     while (1);   
  52. }
  53. //========================================================================================================
  54. void I2C_Process(UINT8 u8DAT)
  55. {
  56.     UINT32 u32Count;

  57. //--------------------------------------------------------------------------------------------
  58. //----  Page Write----------------------------------------------------------------------------
  59. //--------------------------------------------------------------------------------------------
  60.     /* Step1 */
  61.     set_STA;                                    /* Send Start bit to I2C EEPROM */
  62.     clr_SI;
  63.     while (!SI);                                //Check SI set or not
  64.     if (I2STAT != 0x08)                         //Check status value after every step
  65.         I2C_Error();
  66.    
  67.     /* Step2 */
  68.     clr_STA;                                    //STA=0
  69.     I2DAT = (EEPROM_SLA | EEPROM_WR);
  70.     clr_SI;
  71.     while (!SI);                                //Check SI set or not
  72.     if (I2STAT != 0x18)              
  73.         I2C_Error();

  74.     /* Step3 */
  75.     I2DAT = 0x00;                               //address high for I2C EEPROM
  76.     clr_SI;
  77.     while (!SI);                                //Check SI set or not
  78.     if (I2STAT != 0x28)              
  79.         I2C_Error();
  80.                     
  81.     /* Step4 */
  82.     I2DAT = 0x00;                               //address low for I2C EEPROM
  83.     clr_SI;
  84.     while (!SI);                                //Check SI set or not
  85.     if (I2STAT != 0x28)              
  86.         I2C_Error();

  87.     /* Step5 */
  88.     for (u32Count = 0; u32Count < PAGE_SIZE; u32Count++)
  89.     {
  90.         I2DAT = u8DAT;
  91.         clr_SI;
  92.         while (!SI);                            //Check SI set or not
  93.         if (I2STAT != 0x28)              
  94.             I2C_Error();

  95.         u8DAT = ~u8DAT;        
  96.     }

  97. //--------------------------------------------------------------------------------------------
  98. //----  Waitting the ready for I2C write------------------------------------------------------
  99. //--------------------------------------------------------------------------------------------
  100.     /* Step6 */
  101.     do{
  102.         set_STO;
  103.         clr_SI;
  104.         
  105.         set_STA;                                //Check if no ACK is returned by EEPROM, it is under timed-write cycle
  106.         clr_SI;
  107.         while (!SI);                            //Check SI set or not
  108.         if (I2STAT != 0x08)                     //Check status value after every step
  109.             I2C_Error();

  110.         clr_STA;
  111.         I2DAT = (EEPROM_SLA | EEPROM_WR);
  112.         clr_SI;
  113.         while (!SI);                            //Check SI set or not
  114.     }while (I2STAT != 0x18);
  115.    
  116.     /* Step7 */
  117.     set_STO;
  118.     clr_SI;
  119.     while (STO);                                /* Check STOP signal */
  120. //--------------------------------------------------------------------------------------------
  121. //----  Page Read ----------------------------------------------------------------------------
  122. //--------------------------------------------------------------------------------------------
  123.     /* Step8 */
  124.     set_STA;
  125.     clr_SI;         
  126.     while (!SI);                                //Check SI set or not
  127.     if (I2STAT != 0x08)                         //Check status value after every step
  128.         I2C_Error();

  129.     /* Step9 */
  130.     I2DAT = (EEPROM_SLA | EEPROM_WR);
  131.     clr_STA;
  132.     clr_SI;
  133.     while (!SI);                                //Check SI set or not
  134.     if (I2STAT != 0x18)              
  135.         I2C_Error();

  136.     /* Step10 */
  137.     I2DAT = 0x00;                               //address high for I2C EEPROM
  138.     clr_SI;
  139.     while (!SI);                                //Check SI set or not
  140.     if (I2STAT != 0x28)              
  141.         I2C_Error();

  142.     /* Step11 */
  143.     I2DAT = 0x00;                               //address low for I2C EEPROM
  144.     clr_SI;
  145.     while (!SI);                                //Check SI set or not
  146.     if (I2STAT != 0x28)              
  147.         I2C_Error();

  148.     /* Step12 */
  149.     /* Repeated START */
  150.     set_STA;                       
  151.     clr_SI;
  152.     while (!SI);                                //Check SI set or not
  153.     if (I2STAT != 0x10)                         //Check status value after every step
  154.         I2C_Error();
  155.    
  156.     /* Step13 */
  157.     clr_STA;                                    //STA needs to be cleared after START codition is generated
  158.     I2DAT = (EEPROM_SLA | EEPROM_RD);
  159.     clr_SI;
  160.     while (!SI);                                //Check SI set or not
  161.     if (I2STAT != 0x40)              
  162.         I2C_Error();
  163.    
  164.     /* Step14 */
  165.     for (u32Count = 0; u32Count <PAGE_SIZE-1; u32Count++)
  166.     {
  167.         set_AA;
  168.         clr_SI;        
  169.         while (!SI);                            //Check SI set or not

  170.         if (I2STAT != 0x50)              
  171.             I2C_Error();
  172.         
  173.         if (I2DAT != u8DAT)            
  174.             I2C_Error();
  175.         u8DAT = ~u8DAT;
  176.     }
  177.    
  178.     /* Step15 */
  179.     clr_AA;
  180.     clr_SI;
  181.     while (!SI);                                //Check SI set or not
  182.     if (I2STAT != 0x58)              
  183.         I2C_Error();

  184.     /* Step16 */
  185.     set_STO;
  186.     clr_SI;
  187.     while (STO);                                /* Check STOP signal */
  188. }
  189. //========================================================================================================
  190. void main(void)
  191. {
  192.     /* Note
  193.        MCU power on system clock is HIRC (22.1184MHz), so Fsys = 22.1184MHz
  194.     */
  195.    
  196.     Set_All_GPIO_Quasi_Mode;       
  197.     Init_I2C();                                 //initial I2C circuit
  198.     I2C_Process(0x55);                          /* I2C Master will send 0x55,0xAA,.... to slave */
  199.    
  200.     P0 = 0x00;
  201.     P3 = 0x00;
  202.    
  203.     while (1);
  204. /* =================== */
  205. }

gx_huang 发表于 2019-8-26 10:53 | 显示全部楼层
硬件问题硬件方式分析,无非就是RC的充放电波形,如果1K了,上升沿时间还是太长,肯定是总线的电容太大了。
这个完全可以计算的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部