Autor Tema: I2C - Spurious SCL transition detected en proteus  (Leído 4376 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado LucasBols

  • PIC16
  • ***
  • Mensajes: 129
    • Desarrollos y Servicios Digitales
I2C - Spurious SCL transition detected en proteus
« en: 09 de Julio de 2016, 14:47:24 »
hola, buenas tardes,

tengo dos pic, un 16f1827 a 16mhz y un 16f887 a 8mhz, en los dos uso el i2c, y en proteus uso los mismos componentes conectados de la misma forma,


* 887.JPG
(59.78 kB, 773x385 - visto 2239 veces)


* 1827.JPG
(44.83 kB, 442x400 - visto 1957 veces)


en el 887 en SSPADD cargo 0x13 ( SSPADD=(8000000/(4*100000))-1=19 )
en el 1827 en SSP1ADD cargo 0x27 ( SSPADD=(16000000/(4*100000))-1=39 )

en el 1827 anda todo bien, lee la hora, en el 887 anda como debería, también lee la hora, pero me tira 95 mensajes Spurious SCL transition detected,

leí en algunos post que aconsejan usar pullups en lugar de resist comunes para SCL y SDA pero no funcionó,
también probé con resistencias de 4k7 y de 10k a 5v pero tampoco,

tendría que pasar a un proto para ver si funciona,

en ambos pic uso la misma librería,

esta es la del 1827
Código: C
  1. #include "i2c_lib.h"
  2.  
  3. //------------------------------------------------------------------------------
  4. /*
  5.  * Description: Initialize I2C in master mode, Sets the required baudrate
  6.  */
  7. void I2CInit(void)
  8. {
  9.     // BF RCinprocess_TXcomplete; UA dontupdate; SMP High Speed;
  10.     // P stopbit_notdetected; S startbit_notdetected; R_nW write_noTX;
  11.     // CKE Idle to Active; D_nA lastbyte_address;
  12.     SSP1STAT = 0x00;
  13.     // SSPEN enabled; WCOL no_collision; SSPOV no_overflow;
  14.     // CKP Idle:Low, Active:High; SSPM FOSC/4_SSPxADD;
  15.     SSP1CON1 = 0x28;
  16.     // BOEN disabled; AHEN disabled; SBCDE disabled; SDAHT 100ns; DHEN disabled;
  17.     // ACKTIM ackseq; PCIE disabled; SCIE disabled;
  18.     SSP1CON3 = 0x00;
  19.     // Baud Rate Generator Value: SSPADD 39;
  20.     SSP1ADD = 0x27;
  21.  
  22.     /* Byte sent or received */
  23.     // clear the master interrupt flag
  24.     PIR1bits.SSP1IF = 0;
  25.     // enable the master interrupt
  26.     PIE1bits.SSP1IE = 1;
  27. }
  28.  
  29. //------------------------------------------------------------------------------
  30. /*
  31.  * Description: Send a start condition on I2C Bus
  32.  */
  33. void I2CStart()
  34. {
  35.     SSP1CON2bits.SEN = 1; /* Start condition enabled */
  36.     while (SSP1CON2bits.SEN); /* automatically cleared by hardware */
  37.     /* wait for start condition to finish */
  38. }
  39.  
  40. //------------------------------------------------------------------------------
  41. /*
  42.  * Description: Send a stop condition on I2C Bus
  43.  */
  44. void I2CStop()
  45. {
  46.     SSP1CON2bits.PEN = 1; /* Stop condition enabled */
  47.     while (SSP1CON2bits.PEN); /* Wait for stop condition to finish */
  48.     /* PEN automatically cleared by hardware */
  49. }
  50.  
  51. //------------------------------------------------------------------------------
  52. /*
  53.  * Description: Sends a repeated start condition on I2C Bus
  54.  */
  55. void I2CRestart()
  56. {
  57.     SSP1CON2bits.RSEN = 1; /* Repeated start enabled */
  58.     while (SSP1CON2bits.RSEN); /* wait for condition to finish */
  59. }
  60.  
  61. //------------------------------------------------------------------------------
  62. /*
  63.  * Description: Generates acknowledge for a transfer
  64.  */
  65. void I2CAck()
  66. {
  67.     SSP1CON2bits.ACKDT = 0; /* Acknowledge data bit, 0 = ACK */
  68.     SSP1CON2bits.ACKEN = 1; /* Ack data enabled */
  69.     while (SSP1CON2bits.ACKEN); /* wait for ack data to send on bus */
  70. }
  71.  
  72. //------------------------------------------------------------------------------
  73. /*
  74.  * Description: Generates Not-acknowledge for a transfer
  75.  */
  76. void I2CNak()
  77. {
  78.     SSP1CON2bits.ACKDT = 1; /* Acknowledge data bit, 1 = NAK */
  79.     SSP1CON2bits.ACKEN = 1; /* Ack data enabled */
  80.     while (SSP1CON2bits.ACKEN); /* wait for ack data to send on bus */
  81. }
  82.  
  83. //------------------------------------------------------------------------------
  84. /*
  85.  * Description: wait for transfer to finish
  86.  */
  87. void I2CWait()
  88. {
  89.     while ((SSP1CON2 & 0x1F) || (SSP1STAT & 0x04));
  90.     /* wait for any pending transfer */
  91. }
  92.  
  93. //------------------------------------------------------------------------------
  94. /*
  95.  * Arguments: dat - 8-bit data to be sent on bus data can be either address/data byte
  96.  * Description: Send 8-bit data on I2C bus
  97.  */
  98. void I2CSend(unsigned char dat)
  99. {
  100.     SSP1BUF = dat; /* Move data to SSPBUF */
  101.     while (SSP1STATbits.BF); /* wait till complete data is sent from buffer */
  102.     I2CWait(); /* wait for any pending transfer */
  103. }
  104.  
  105. //------------------------------------------------------------------------------
  106. /*
  107.  * Return: 8-bit data read from I2C bus
  108.  * Description: read 8-bit data from I2C bus
  109.  */
  110. unsigned char I2CRead(void)
  111. {
  112.     unsigned char temp;
  113.  
  114.     /* Reception works if transfer is initiated in read mode */
  115.     SSP1CON2bits.RCEN = 1; /* Enable data reception */
  116.     while (!SSP1STATbits.BF); /* wait for buffer full */
  117.     temp = SSP1BUF; /* Read serial buffer and store in temp register */
  118.     I2CWait(); /* wait to check any pending transfer */
  119.     return temp; /* Return the read data from bus */
  120. }

y esta es la del 887
Código: C
  1. #include "i2c_lib.h"
  2.  
  3. //------------------------------------------------------------------------------
  4. /*
  5.  * Description: Initialize I2C in master mode, Sets the required baudrate
  6.  */
  7. void I2CInit(void)
  8. {
  9.     TRISC3 = 1; /* SDA and SCL as input pin */
  10.     TRISC4 = 1; /* these pins can be configured either i/p or o/p */
  11.     SSPSTATbits.SMP = 1; /* Slew rate disabled */
  12.     SSPCONbits.SSPEN = 1; /* Enables the serial port and configures the SDA and
  13.                            * SCL pins as the source of the serial port pins */
  14.     SSPCON = 0x28; /* SSPEN = 1, I2C Master mode, clock = FOSC/(4 * (SSPADD + 1)) */
  15.     /*
  16.      * Velocidad=Fosc/(4*(SSPADD+1))
  17.      * SSPADD=(Fosc/(4*Velocidad))-1
  18.      * SSPADD=(8000000/(4*100000))-1
  19.      */
  20.     SSPADD = 0x13; /* 100Khz @ 8Mhz Fosc */
  21. }
  22.  
  23. //------------------------------------------------------------------------------
  24. /*
  25.  * Description: Send a start condition on I2C Bus
  26.  */
  27. void I2CStart()
  28. {
  29.     SEN = 1; /* Start condition enabled */
  30.     while (SEN); /* automatically cleared by hardware */
  31.     /* wait for start condition to finish */
  32. }
  33.  
  34. //------------------------------------------------------------------------------
  35. /*
  36.  * Description: Send a stop condition on I2C Bus
  37.  */
  38. void I2CStop()
  39. {
  40.     PEN = 1; /* Stop condition enabled */
  41.     while (PEN); /* Wait for stop condition to finish */
  42.     /* PEN automatically cleared by hardware */
  43. }
  44.  
  45. //------------------------------------------------------------------------------
  46. /*
  47.  * Description: Sends a repeated start condition on I2C Bus
  48.  */
  49. void I2CRestart()
  50. {
  51.     RSEN = 1; /* Repeated start enabled */
  52.     while (RSEN); /* wait for condition to finish */
  53. }
  54.  
  55. //------------------------------------------------------------------------------
  56. /*
  57.  * Description: Generates acknowledge for a transfer
  58.  */
  59. void I2CAck()
  60. {
  61.     ACKDT = 0; /* Acknowledge data bit, 0 = ACK */
  62.     ACKEN = 1; /* Ack data enabled */
  63.     while (ACKEN); /* wait for ack data to send on bus */
  64. }
  65.  
  66. //------------------------------------------------------------------------------
  67. /*
  68.  * Description: Generates Not-acknowledge for a transfer
  69.  */
  70. void I2CNak()
  71. {
  72.     ACKDT = 1; /* Acknowledge data bit, 1 = NAK */
  73.     ACKEN = 1; /* Ack data enabled */
  74.     while (ACKEN); /* wait for ack data to send on bus */
  75. }
  76.  
  77. //------------------------------------------------------------------------------
  78. /*
  79.  * Description: wait for transfer to finish
  80.  */
  81. void I2CWait()
  82. {
  83.     while ((SSPCON2 & 0x1F) || (SSPSTAT & 0x04));
  84.     /* wait for any pending transfer */
  85. }
  86.  
  87. //------------------------------------------------------------------------------
  88. /*
  89.  * Arguments: dat - 8-bit data to be sent on bus data can be either address/data byte
  90.  * Description: Send 8-bit data on I2C bus
  91.  */
  92. void I2CSend(unsigned char dat)
  93. {
  94.     SSPBUF = dat; /* Move data to SSPBUF */
  95.     while (BF); /* wait till complete data is sent from buffer */
  96.     I2CWait(); /* wait for any pending transfer */
  97. }
  98.  
  99. //------------------------------------------------------------------------------
  100. /*
  101.  * Return: 8-bit data read from I2C bus
  102.  * Description: read 8-bit data from I2C bus
  103.  */
  104. unsigned char I2CRead(void)
  105. {
  106.     unsigned char temp;
  107.  
  108.     /* Reception works if transfer is initiated in read mode */
  109.     RCEN = 1; /* Enable data reception */
  110.     while (!BF); /* wait for buffer full */
  111.     temp = SSPBUF; /* Read serial buffer and store in temp register */
  112.     I2CWait(); /* wait to check any pending transfer */
  113.     return temp; /* Return the read data from bus */
  114. }

les agradezco cualquier ayuda,

muchas gracias,

saludos,
Un experto es alguien que te explica algo sencillo de forma confusa de tal manera que te hace pensar que la confusión sea culpa tuya.

DSD http://www.dysd.com.ar/

Desconectado PalitroqueZ

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 5490
    • Electrónica Didacta
Re:I2C - Spurious SCL transition detected en proteus
« Respuesta #1 en: 09 de Julio de 2016, 15:27:47 »
LucasBols

- en vez de la fuente DC de 5volts utiliza el terminal POWER (icono Terminal Mode)
- el cristal es de 32768Hz o 32.768Khz, aunque creo que no haría falta colocar el cristal (no recuerdo bien).
- una pull-up va bien en la simulación en el rango de 1k a 10k

La propiedad privada es la mayor garantía de libertad.
Friedrich August von Hayek


 

anything