Autor Tema: Slave PIC - I2C - XC8  (Leído 9021 veces)

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

Desconectado Tercio

  • PIC10
  • *
  • Mensajes: 27
Slave PIC - I2C - XC8
« en: 13 de Agosto de 2014, 19:21:55 »
Hola,

Les comento mi duda ya que he revisado el foro pero no llego a una solución, resulta que he probado la comunicación I2C con el pic16lf1937 y una EEPROM con XC8, haciendo pruebas de escritura y de lectura de la eeprom todo funciono muy bien, pero ahora quiero hacer la comunicación entre 2 PIC por I2C y veo que el compilador XC8 no brinda buen soporte para esto. Por lo tanto para mi configuración PIC Master me he guiado con utilizada con la EEPROM en la primera prueba que hice pero la configuración del PIC Slave ahora es la que me tiene confundido, quisiera saber si me pueden brindar ayuda con información o que configuración debo implementar para el PIC Slave. Espero me puedan ayudar muchas gracias. 

Desconectado Tercio

  • PIC10
  • *
  • Mensajes: 27
Re: Slave PIC - I2C - XC8
« Respuesta #1 en: 14 de Agosto de 2014, 18:15:57 »
Hola,

Veo que nadie da respuesta a esta duda, La verdad he seguido intentando pero no he logrado hacer la comunicación me he guiado con este blog (http://robotypic.blogspot.com.es/2010/10/comunicacion-via-i2c-entre-dos-pic.html) pero esta desarrollado en CCS y estoy trabajando con XC8. Y aun así no logro obtener buenos resultados.
 

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: Slave PIC - I2C - XC8
« Respuesta #2 en: 14 de Agosto de 2014, 20:18:04 »
Hola,

Veo que nadie da respuesta a esta duda, La verdad he seguido intentando pero no he logrado hacer la comunicación me he guiado con este blog (http://robotypic.blogspot.com.es/2010/10/comunicacion-via-i2c-entre-dos-pic.html) pero esta desarrollado en CCS y estoy trabajando con XC8. Y aun así no logro obtener buenos resultados.
 

  Nunca he implementado I2C Slave, de hecho, tampoco tengo rutinas para ello. Sí me hice unas para master. Imagino que no debería ser muy complicado guiándose con lo explicado en el datasheet.

  ¿Podrías mostrar tu código de slave, utilizando la opción GeSHi del editor de mensajes del foro? Seguramente al ver el código, mas usuarios podrán dar sus ideas
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado Tercio

  • PIC10
  • *
  • Mensajes: 27
Re: Slave PIC - I2C - XC8
« Respuesta #3 en: 21 de Agosto de 2014, 13:20:44 »
Hola,
He usado un ejemplo encontrado en microchip (XC8) y lo he utilizado con el PIC16lf1937, estoy usado este pic tanto para Master como para Slave, El ejemplo esta diseñado para leer y escribir del Master al Slave, yo ya lo he implementado, ahora cuando trato de hacer la simulación en Proteus no se como hacer para verificar esta comunicación, ya lo he hecho de varias formas pero entonces no se si es porque estoy haciendo mal el diseño en Proteus, Entonces quisiera que me ayudaran en esta simulación para verificar que los códigos de Master y Slave funcionan correctamente y de ser así agradecer por la ayuda.   

Anexo los dos códigos usados el Master I2C y Slave I2C.

******************************I2C MASTER DRIVER CODE********************************************   
Código: C
  1. /*CODE FUNCTION:
  2.  The code implements the MSSP (or SSP) module as an I2C master.
  3.  The master will transmit a set up data from an array to the slave, and after
  4.  each byte is transmitted, that location in the array is overwritten with a
  5.  value of 0x00. This helps to make sure that the data was transmitted properly.
  6.  After the data is transmitted, the master then reads data from an array in the
  7.  slave, and loads the data into another array within the master.*/
  8.  
  9.  
  10. #include <xc.h>
  11. #include <pic16lf1937.h>
  12.  
  13.  
  14. // CONFIG1
  15. #pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)-Internal oscillator (31 kHz to 32 MHz).
  16. #pragma config WDTE = ON       // Watchdog Timer Enable (WDT disabled)
  17. #pragma config PWRTE = ON       // Power-up Timer Enable (PWRT enabled)
  18. #pragma config MCLRE = ON      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
  19. #pragma config CP = ON          // Flash Program Memory Code Protection (Program memory code protection is enabled)
  20. #pragma config CPD = ON         // Data Memory Code Protection (Data memory code protection is enabled)
  21. #pragma config BOREN = ON      // Brown-out Reset Enable (Brown-out Reset disabled)
  22. #pragma config CLKOUTEN = OFF    // Clock Out Enable (CLKOUT function is enabled on the CLKOUT pin)
  23. #pragma config IESO = ON        // Internal/External Switchover (Internal/External Switchover mode is enabled)
  24. #pragma config FCMEN = ON      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
  25.  
  26. // CONFIG2
  27. #pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
  28. #pragma config PLLEN = ON       // PLL Enable (4x PLL enabled)
  29. #pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
  30. #pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
  31. #pragma config LVP = ON         // Low-Voltage Programming Enable (Low-voltage programming enabled)
  32.  
  33. #define RX_ELMNTS 32
  34.  
  35. // array for master to write data from slave
  36. volatile unsigned char I2C_Array_Rx[RX_ELMNTS] = 0;
  37.  
  38. // array for master to write to
  39. volatile unsigned char I2C_Array_Tx[RX_ELMNTS] =
  40. {0x09,0x09,0x13,0x14,0x15,0x16,0x17,0x18,
  41.  0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0xCF,
  42.  0xCE,0xCD,0xCC,0xCB,0xCA,0xC9,0xC8,0xC7,
  43.  0xC6,0xC5,0xC4,0xC3,0xC2,0xC1,0xC0,0xAA};
  44.  
  45. unsigned char I2C_slave_write_add = 0x30; //slave address R/nW = 0(write)
  46. unsigned char I2C_slvae_read_add = 0x31;  //slave address R/nW =1 (Read)
  47. unsigned char BRG_val = 0x9;             //0x27 sets the SCL freq to 100kHz
  48.  
  49. unsigned int index_i2c = 0;               //index pointer
  50. unsigned char junk = 0;                   //place to put unnecessary data
  51. unsigned char clear = 0x00;               //used to clear array location
  52. unsigned char init_start = 1;               // used to get start bit set
  53. unsigned char stop = 0;                     // used to know when to stop
  54. unsigned char write_to_slave = 1;           // used to set up master transmission
  55. unsigned char trans_wrt_add = 1;            // used to set up address for write
  56. unsigned char init_trans_data = 0;          // used to set up data transmission
  57. unsigned char init_mstr_rec = 0;            // used to set up master reception
  58. unsigned char rec_byte = 0;                 // used to know when byte received
  59. unsigned char set_RCEN = 0;                 // used to set RCEN bit
  60. unsigned char trans_data = 0;               // used to get transmission going
  61. unsigned char done = 0;                     // used to know when finished
  62. unsigned char read_from_slave = 0;          // used to set up reception routine
  63. unsigned char trans_rd_add = 1;             // used to set up address for read
  64. unsigned char read_rec_byte = 0;            // used to read data into array
  65. unsigned char set_ACKEN = 0;                // used to set ACKEN bit
  66.  
  67.  
  68. void initialize(void);                      //initialize micro routine
  69.  
  70. /***********************MAIN ROUTINE**********************************/
  71.  
  72. void main(void)
  73. {
  74.     initialize();               //go get initialized
  75.     while (1)                   //main while() loop
  76. {
  77.  
  78.         asm("CLRWDT");          //clear WDT
  79.         if (write_to_slave)     //get set to go write to slave
  80.         {
  81.             if(init_start)      //get ready to start
  82.             {
  83.                 SSPCON2bits.SEN = 1; //Initiate START condition
  84.                 init_start = 0;
  85.             }
  86.             if(init_trans_data)  //get ready to transmit data
  87.             {
  88.                 trans_data = 1;
  89.                 init_trans_data = 0;
  90.             }
  91.             if(done)             //when all data is transferred
  92.             {                    //send stop bit
  93.                 stop = 1;
  94.                 done = 0;
  95.                 SSPCON2bits.PEN = 1; //stop bit set
  96.             }
  97.         }//end transmission
  98.  
  99.         if ((!write_to_slave)&&(!read_from_slave))  //get ready to now read
  100.         {
  101.             read_from_slave = 1;                    //get read routines going
  102.             done = 0;
  103.             index_i2c = 0;
  104.             init_start = 1;                         //get ready to start
  105.         }
  106.  
  107.         if (read_from_slave)                        //read from salve
  108.         {
  109.             if(init_start)                          //set up start condition
  110.             {
  111.                 SSPCON2bits.SEN = 1;                //Initiate START condition
  112.                 init_start = 0;
  113.             }
  114.             if(init_mstr_rec)                       //get ready to receive data
  115.             {
  116.                 set_RCEN = 1;                       //set master into receive modo
  117.                 init_mstr_rec = 0;
  118.             }
  119.             if(rec_byte)                            //check to see if data arrived
  120.             {
  121.                 read_rec_byte = 1;
  122.             }
  123.             if(set_ACKEN)                           //set up ACKEN bit
  124.             {
  125.                 set_ACKEN = 0;
  126.                 init_mstr_rec = 1;
  127.                 ACKEN = 1;                          //
  128.             }
  129.             if(done)                                //if array is full time to stop
  130.             {
  131.                 stop = 1;
  132.                 SSPCON2bits.PEN = 1;                //set stop bit
  133.             }
  134.         }//end read routine
  135.     }//end while()
  136. }//end main
  137.  
  138. /******************************************************************************/
  139.  
  140. /********************************INITIALIZE ROUTINE ***************************/
  141.  
  142. void initialize(void)
  143. {
  144. //uC SET UP
  145.     OSCCON = 0X68;          //Internal OSC @ 4MHz
  146.     OPTION_REG = 0b11010111;
  147.     WDTCON = 0b00010111;    //prescaler 1:65536
  148.                             //period is 2 sec (RESET value)
  149.     PORTC = 0x00;           //Clear PORTC
  150.     LATC = 0x00;            //Clear PORTC latches
  151.     TRISC = 0b00011000;     //Set RC3, RC4 as inputs for I2C
  152.  
  153.  
  154. //I2C MASTER MODULE SET UP
  155.     SSPSTAT = 0b10000000;  //Slew rate control disabled for
  156.                             //standar speed mode (100 kHz)
  157.     SSPCON1 = 0b00101000;   //Enable serial port, I2C master mode,
  158.                             //clock=Fosc/(4*(SSPAD+1))
  159.     SSPCON3bits.SDAHT = 1;  //Minimum of 300 ns hold time on SDA
  160.                             //after the falling edge of SCL
  161.     SSPADD = BRG_val;       //This sets Baud rate
  162.     SSPIF = 0;              // Clear the serial port interrupt flag
  163.     BCLIF = 0;              // Clear the bus coll interrupt flag
  164.     BCLIE = 1;              // Enable bus collision interrupts
  165.     SSPIE = 1;              // Enable serial port interrupts
  166.     PEIE = 1;               // Enable peripheral interrupts
  167.     GIE = 1;                // Enable global interrupts
  168. }
  169. /******************************************************************************/
  170.  
  171. /****************************** ISR ROUTINE ***********************************/
  172. void interrupt ISR(void)
  173. {
  174.     if (SSPIF)                                      // is it an SSP interrupt?
  175.     {
  176.         if(write_to_slave)                          // write to slave
  177.         {
  178.             if(!done)                               // if not done, continue
  179.             {
  180.                 if(trans_wrt_add)                   // get ready to transmit
  181.                 {                                   // address with write bit enabled
  182.                     SSPBUF = I2C_slave_write_add;   // load buffer with write address
  183.                     trans_wrt_add = 0;
  184.                     init_trans_data = 1;
  185.                 }
  186.                 if(trans_data)                      // ready to transmit
  187.                 {
  188.                     if(index_i2c < RX_ELMNTS)       // make sure valid data
  189.                     {
  190.                         SSPBUF = I2C_Array_Tx[index_i2c];   // load buffer with data
  191.                         I2C_Array_Tx[index_i2c++] = clear;  // clear that location
  192.                     }                                       // and increment index
  193.                     else
  194.                     {
  195.                         trans_data = 0;                     // done transmitting
  196.                         done = 1;
  197.                     }
  198.                 }
  199.             }
  200.  
  201.             if (stop)                                       // done transmitting
  202.             {
  203.                 write_to_slave = 0;                         // clear so no more data transmitted
  204.                 stop = 0;
  205.             }
  206.         }
  207.         if (read_from_slave)                                // read from slave
  208.         {
  209.             if(!done)                                       // if not done continue
  210.             {
  211.                 if(trans_rd_add)                            // set up read address
  212.                 {
  213.                     SSPBUF = I2C_slvae_read_add;            // address and read bit
  214.                     trans_rd_add = 0;
  215.                     init_mstr_rec = 1;
  216.                 }
  217.                 if(set_RCEN)                                // set up module for read
  218.                 {
  219.                     set_RCEN = 0;
  220.                     SSPCON2bits.RCEN = 1;                   // set RCEN to enable read
  221.                     rec_byte = 1;
  222.                 }  
  223.                     if (read_rec_byte)                      // reading data
  224.                     {
  225.                         if(index_i2c < RX_ELMNTS){          // make sure valid location
  226.                         read_rec_byte = 0;
  227.                         rec_byte = 0;
  228.                         I2C_Array_Rx[index_i2c] = SSPBUF;   // load array with data
  229.                         index_i2c++;                        // increment counter
  230.                         set_ACKEN = 1;                      // get ready to ACK
  231.                     }
  232.                     else
  233.                     {                                       // received all data
  234.                         init_mstr_rec = 0;
  235.                         rec_byte = 0;
  236.                         read_rec_byte = 0;
  237.                         done = 1;
  238.                     }
  239.                 }
  240.             }
  241.             if(stop)
  242.             {
  243.                 read_from_slave = 0;                        // clear so no more data is received
  244.             }
  245.         }
  246.     }
  247.  
  248.     if (BCLIF)                                              // Did a bus collision occur?
  249.     {
  250.         junk = SSPBUF;                                      // dummy read to clear BF bit
  251.         BCLIF = 0;                                          // clear BCLIF flag bit
  252.     }
  253.     SSPIF = 0;                                              // clear SSPIF flag bit
  254. }//end of ISR

***********************************************************************************************

******************************I2C SLAVE DRIVER CODE ********************************************   

Código: C
  1. /*CODE FUNCTION:
  2.  The code implements the MSSP (or SSP) module as an I2C slave.
  3.  This will allow the user to read from, or write to, a data array
  4.  (32 bytes long). There is also a 'fail-safe' built in to protect from writing
  5.  data into critical memory locations. It is important to keep in mind that this
  6.  code is for demonstration of the MSSP module for slave I2C communications.
  7.  It does not include other interrupt possibilities, which would need to be
  8.  added, and may require this code to be modified. Also, for simplicity, the
  9.  initialization of the basic necessary registers are done in this C file.
  10.  This can also be done in a separate header (.h) file. Having a separate .h
  11.  file can make it easy to re-use the code in multiple applications.*/
  12.  
  13. #include <xc.h>
  14. #include <pic16lf1937.h>
  15.  
  16. // CONFIG1
  17. #pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)-Internal oscillator (31 kHz to 32 MHz).
  18. #pragma config WDTE = ON       // Watchdog Timer Enable (WDT disabled)
  19. #pragma config PWRTE = ON       // Power-up Timer Enable (PWRT enabled)
  20. #pragma config MCLRE = ON      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
  21. #pragma config CP = ON          // Flash Program Memory Code Protection (Program memory code protection is enabled)
  22. #pragma config CPD = ON         // Data Memory Code Protection (Data memory code protection is enabled)
  23. #pragma config BOREN = ON      // Brown-out Reset Enable (Brown-out Reset disabled)
  24. #pragma config CLKOUTEN = OFF    // Clock Out Enable (CLKOUT function is enabled on the CLKOUT pin)
  25. #pragma config IESO = ON        // Internal/External Switchover (Internal/External Switchover mode is enabled)
  26. #pragma config FCMEN = ON      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
  27.  
  28. // CONFIG2
  29. #pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
  30. #pragma config PLLEN = ON       // PLL Enable (4x PLL enabled)
  31. #pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
  32. #pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
  33. #pragma config LVP = ON         // Low-Voltage Programming Enable (Low-voltage programming enabled)
  34.  
  35. #define RX_ELMNTS 32
  36. unsigned char I2C_slave_address = 0x30;  //slave address
  37.  
  38. // array for master to read from
  39. volatile unsigned char I2C_Array_Tx[RX_ELMNTS] =
  40. {0xAA,0xEE,0xDD,0xCC,0xBB,0xAA,0x99,0x88,
  41. 0x77,0x66,0x55,0x44,0x33,0x22,0x11,0xFA,
  42. 0xEA,0xDA,0xCA,0xBA,0xFB,0xFC,0xFD,0xFE,
  43. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
  44.  
  45. // array for master to write to
  46. volatile unsigned char I2C_Array_Rx[RX_ELMNTS] = 0;
  47.  
  48. unsigned int index_i2c = 0;                     // index pointer
  49. unsigned char junk = 0;                         // used to place unnecessary data
  50. unsigned char clear = 0x00;                     // used to clear array location once
  51.                                                 // it has been read
  52.  
  53. void initialize(void);                          // Initialize routine
  54.  
  55. /*************************** MAIN ROUTINE *************************************/
  56. void main(void){
  57.     initialize();                               // call initialize routine
  58.     while(1)                                    // main while() loop
  59.     {                                           // program will wait here for ISR to be called
  60.         asm("CLRWDT");                          // clear WDT
  61.     }
  62. }// end main
  63. /******************************************************************************/
  64.  
  65. /**************************** INITIALIZE ROUTINE ******************************/
  66.  
  67. void initialize(void)
  68. {
  69.  //uC SET UP
  70.     OSCCON = 0x68;                              // Internal OSC @ 4MHz
  71.     OPTION_REG = 0b11010111;                    // WPU disabled, INT on rising edge, FOSC/4
  72.                                                 // Prescaler assigned to TMR0, rate @ 1:256
  73.     WDTCON = 0b00010111;                        // Prescaler 1:65536
  74.                                                 // period is 2 sec (RESET value)
  75.     PORTC = 0x00;                               // Clear PORTC
  76.     LATC = 0x00;                                // Clear PORTC latches
  77.     TRISC = 0b00011000;                         // Set RC3, RC4 as inputs for I2C
  78. //I2C SLAVE MODULE SET UP
  79.     SSPSTAT = 0b10000000;                       // Slew rate control disabled for standard
  80.                                                 // speed mode (100 kHz and 1 MHz)
  81.     SSPCON1 = 0b00110110;                       // Enable serial port, I2C slave mode,
  82.                                                 // 7-bit address
  83.     SSPCON2bits.SEN = 1;                        // Clock stretching is enabled
  84.     SSPCON3bits.BOEN = 1;                       // SSPBUF is updated and NACK is generated
  85.                                                 // for a received address/data byte,
  86.                                                 // ignoring the state of the SSPOV bit
  87.                                                 // only if the BF bit = 0
  88.     SSPCON3bits.SDAHT = 1;                      // Minimum of 300 ns hold time on SDA after
  89.                                                 // the falling edge of SCL
  90.     SSPCON3bits.SBCDE = 1;                      // Enable slave bus collision detect interrupts
  91.     SSPADD = I2C_slave_address;                 // Load the slave address
  92.     SSPIF = 0;                                  // Clear the serial port interrupt flag
  93.     BCLIF = 0;                                  // Clear the bus collision interrupt flag
  94.     BCLIE = 1;                                  // Enable bus collision interrupts
  95.     SSPIE = 1;                                  // Enable serial port interrupts
  96.     PEIE = 1;                                   // Enable peripheral interrupts
  97.     GIE = 1;                                    // Enable global interrupts
  98. }//end initialize
  99. /******************************************************************************/
  100.  
  101. /*************************** ISR ROUTINE **************************************/
  102. void interrupt ISR(void)
  103. {
  104.     if(SSPIF)                                   // check to see if SSP interrupt
  105.     {
  106.         if(SSPSTATbits.R_nW)                    // Master read (R_nW = 1)
  107.         {
  108.             if(!SSPSTATbits.D_nA)               // last byte was an address (D_nA = 0)
  109.             {
  110.                 junk = SSPBUF;                  // dummy read to clear BF bit
  111.                 index_i2c = 0;                  // clear index pointer
  112.                 if(index_i2c < RX_ELMNTS)
  113.                 {                               // Does data exceed number of allocated bytes?
  114.                     SSPBUF = I2C_Array_Tx[index_i2c];   // load SSPBUF with data
  115.                     I2C_Array_Tx[index_i2c++] = clear;  // clear that location
  116.                 }                                       // and increment index
  117.                 else                            // trying to exceed array size
  118.                 {
  119.                     junk = SSPBUF;              // dummy read to clear BF bit
  120.                 }
  121.                 SSPCON1bits.CKP = 1;            // release CLK
  122.             }
  123.             if(SSPSTATbits.D_nA)                // last byte was data
  124.             {
  125.                 if (index_i2c < RX_ELMNTS)
  126.                 {                               // Does data exceed number of allocated bytes?
  127.                     SSPBUF = I2C_Array_Tx[index_i2c];   // load SSPBUF with data
  128.                     I2C_Array_Tx[index_i2c++] = clear;  // clear that location
  129.                 }                                       // and increment index
  130.                 else
  131.                 {
  132.                     junk = SSPBUF;                      // dummy read to clear BF bit
  133.                 }
  134.                 SSPCON1bits.CKP = 1;                    // release CLK
  135.             }
  136.         }
  137.         if(!SSPSTATbits.R_nW)                   // master write (R_nW = 0)
  138.         {
  139.            if(!SSPSTATbits.D_nA)                // last byte was an address (D_nA = 0)
  140.            {
  141.                junk = SSPBUF;                   // read buffer to clear BF
  142.                SSPCON1bits.CKP = 1;             // release CLK
  143.            }
  144.            if(SSPSTATbits.D_nA)                 // last byte was data (D_nA = 1)
  145.            {
  146.                if(index_i2c < RX_ELMNTS)
  147.                {                                // Does data exceed number of allocated bytes?
  148.                    I2C_Array_Rx[index_i2c++] = SSPBUF;
  149.                }                                // load array with data
  150.                else
  151.                {
  152.                    index_i2c = 0;               // reset the index pointer
  153.                }
  154.                if(SSPCON1bits.WCOL)             // Did a write collision occur?
  155.                {
  156.                    SSPCON1bits.WCOL = 0;        // clear WCOL bit
  157.                    junk = SSPBUF;               // clear SSPBUF
  158.                }
  159.                SSPCON1bits.CKP = 1;             // release CLK
  160.            }
  161.         }
  162.     }
  163.     if(BCLIF)                                   // Did a bus collision occur?
  164.     {
  165.         junk = SSPBUF;                          // clear SSPBUF
  166.         BCLIF = 0;                              // clear BCLIF
  167.         SSPCON1bits.CKP = 1;                    // Release CLK
  168.     }
  169.         SSPIF = 0;                              // clear SSPIF
  170. }

**************************************************************************************************

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: Slave PIC - I2C - XC8
« Respuesta #4 en: 21 de Agosto de 2014, 21:11:55 »
  ¿Puedes subir una captura de tu circuito? Me ha pasado que para que funcione la simulación de I2C, las resistencias en el bus tienen que ser del tipo PULLUP ya que con las comunes no funciona
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado Tercio

  • PIC10
  • *
  • Mensajes: 27
Re: Slave PIC - I2C - XC8
« Respuesta #5 en: 22 de Agosto de 2014, 14:04:11 »
Si mira:


Este es el circuito con que estoy simulando. Espero este bien. Los Leds que están hay los tengo en una comparación con los datos que intercambian el Master y el Slave. Espero este bien el diseño en Proteus.      
« Última modificación: 22 de Agosto de 2014, 14:17:58 por Tercio »

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: Slave PIC - I2C - XC8
« Respuesta #6 en: 23 de Agosto de 2014, 14:35:56 »
  ¿Y de que tipo son R1 y R2?
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado Tercio

  • PIC10
  • *
  • Mensajes: 27
Re: Slave PIC - I2C - XC8
« Respuesta #7 en: 25 de Agosto de 2014, 12:41:18 »
PULL UP

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: Slave PIC - I2C - XC8
« Respuesta #8 en: 25 de Agosto de 2014, 20:15:49 »
¿Qué ocurre si colocas las resistencias de pullup a 5V en lugar de 3.6V?
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado Tercio

  • PIC10
  • *
  • Mensajes: 27
Re: Slave PIC - I2C - XC8
« Respuesta #9 en: 27 de Agosto de 2014, 15:55:50 »
Todo sigue igual...  :?

Desconectado Alejandro793

  • PIC10
  • *
  • Mensajes: 7
Re:Slave PIC - I2C - XC8
« Respuesta #10 en: 27 de Febrero de 2021, 10:49:38 »
Puedes usar el monitor i2c de proteus para verificar la comunicacion de los dos pic  yo recientemente estoy trabajando la comunicacion i2c en modo slave https://i0.wp.com/www.huborarduino.com/images/programacion/Lec11_002.jpg el