• AVR Freaks

I2C Slave not working

Author
newmelon
New Member
  • Total Posts : 14
  • Reward points : 0
  • Status: offline
2019/12/04 05:12:39 (permalink)
0

I2C Slave not working

Dear all
I am working on I2C as Slave since several days now, dont get it working! As far as I have understood from the Microchip specs (microchip.com/downloads/en/Appnotes/00000734C.pdf), the ACK bit gets generated automatically by the hardware? (page 4, point 4)
 
PIC16F15354
 
I tried the code and Ideas from microchip.com/forums/m1033803.aspx , but theres just nothing!
Can anyone please have a look at my code and tell me what I am doing wrong:
Pins are declared as Input and as Digital per ANSEL. I double checked if the pins are ok for the MSSP Module.
 
PPS:
    
 
 
 
    unsigned char state=GIE;
 
 
 
    // unlock PPS
    GIE=0; // disable INT
    PPSLOCK=0x55;
    PPSLOCK=0xAA;
    PPSLOCKED=0;
 
 
 
 
 
 
 
    // I2C MAIN
    SSP1DATPPS = 0x14; // RC4 -> SDA1
    RC3PPS = 0x15; // RC3 -> SCL1
    RC4PPS = 0x16; // RC4 -> SDA1
    SSP1CLKPPS = 0x13; // RC3 -> SCL1
 
 
 
 
 
 
 
    // Lock PPS
 
 
 
    PPSLOCK=0x55;
    PPSLOCK=0xAA;
    PPSLOCKED=1;  
    GIE=state;
 
 
 

 
// MSSP Config + Interrupt
   
 
 
 
     #define I2C_ADDR 0x76
    
    INTCONbits.GIE=0;
    PIE3bits.SSP1IE=1; // Enable MSSP1 Enable Interrupt
    INTCONbits.PEIE=1;
    INTCONbits.GIE=1;
   
    SSP1CON1bits.SSPEN = 0;
    SSP1CON1 = 0b01110110; // 7-bit address slave mode with start/stop interrupts disabled
    SSP1CON2 = 0b00000001; // Clock stretching Enabled
    SSP1CON3 = 0b00000000;
    SSP1ADD = (I2C_ADDR << 1);
    SSP1STAT = 0b00000000;
    SSP1CON1bits.SSPEN = 1;
 
 
 

 
 
I also tried another code for the ISR:

 
 
 
void __interrupt () interruptroutine(){
     char dummy, data;
 
 
 

    if(PIR3bits.SSP1IF){//2)
        PIR3bits.SSP1IF=0;

        //Master wants to write, Slave Reads
        if (!SSP1STATbits.R_W) {
            //adress match

            // Adresse
            if (!SSP1STATbits.D_A) {
                dummy=SSP1BUF; //read, 6)
                SSP1STATbits.BF=0;
                SSP1CON1bits.CKP=1;
                PIR3bits.SSP1IF=0;
                return;
            }// Daten
            else if (SSP1STATbits.D_A) {
                messagec=SSP1BUF;
                //SSP1STATbits.BF=0;
                SSP1CON1bits.CKP=1;
                PIR3bits.SSP1IF=0;
                return;
            }
        } else if (SSP1STATbits.R_W) {
                   //nothing
        }
    }
 
}
 
 
 

 
On the Oscilloscope I just see 3-5 clocks
 
I even tried the code from Microchip: but also same problem..
microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en011798
Can anyone please help
 
Many thanks
post edited by newmelon - 2019/12/04 05:37:08
#1

2 Replies Related Threads

    oliverb
    Super Member
    • Total Posts : 245
    • Reward points : 0
    • Joined: 2009/02/16 13:12:38
    • Location: 0
    • Status: offline
    Re: I2C Slave not working 2019/12/04 05:59:00 (permalink)
    +1 (1)
    I believe MCC can generate a working I2C slave. You might not want to use it in its entirity, but having a working example usually helps.
    Otherwise there was an example posted for an 18F PIC some years ago, I can't find it right now though but I may still have a link to it.
     
    Found it: https://www.microchip.com/forums/m741878.aspx but be warned it dates back to 2013 and C18. It isn't hard to convert to XC8 though.
    post edited by oliverb - 2019/12/06 13:21:16
    #2
    ric
    Super Member
    • Total Posts : 24646
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: I2C Slave not working 2019/12/04 16:25:40 (permalink)
    0
    I don't see any code to switch pins RC3 and RC4 from analog to digital mode.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5