• AVR Freaks

Hot!dsPIC33EP256GP502 Enabling I2C_1 Slave ISR?

Author
arigead
Super Member
  • Total Posts : 455
  • Reward points : 0
  • Joined: 2011/02/07 06:58:31
  • Location: 0
  • Status: offline
2021/02/16 15:22:00 (permalink)
0

dsPIC33EP256GP502 Enabling I2C_1 Slave ISR?

I'm trying to use a dsPIC33EP256GP502 to emulate an I2C EEPROM chip. Trying to get the dsPIC33 to act as the EEPROM and answer memory read requests. This involves acting as an I2C Slave device and wanted to make the code interrupt driven. So there's a lot of code to go into an ISR, but for the moment I never get any interrupt being triggered.
 
I can trigger the other device to start a Memory read with a GPIO Pin going high, and just as a test I've got the dsPIC33 pulling a GPIO pin low in the ISR so that I can see the ISR has occurred, but it never gets an interrupt. I've tested the ISR indication pin and it is working, so how come no ISR? I'm scratching my head and rereading data sheets but don't see why no ISR.
 
I've got minimal code just turning on the I2C for the moment and enabling interrupts, obviously there's a lot more to it then that, but for the moment I just wanted to see that I'm getting an ISR.
 
I'll attach a screen shot of what I'm seeing on a logic analyser. Basically I trigger the memory read by setting a GPIO Pin high, the read operation starts on the I2C Bus, but no ISR :(
 
#include <xc.h>

void __attribute__((__interrupt__, __no_auto_psv__)) _SI2C1Interrupt(void)
{
 LATBbits.LATB13 = 0;   // Indicate an Interrupt occurred
}

int main(void)
{
 uint32_t delay;

 /*
  * Set out watch pin high
  */
 TRISBbits.TRISB13 = 0;
 LATBbits.LATB13 = 1;

 /*
  * Pin RB8 is Clock, set input/Open Drian
  */
 ODCBbits.ODCB8 = 1;
  TRISBbits.TRISB8 = 1;

 /*
  * Pin RB9 is out Data pin SDA, Set input/Open Drain
  */
 ODCBbits.ODCB9 = 1;
 TRISBbits.TRISB9 = 1;

 /*
  * Enable I2C1 Interrupts
  */
 IFS1bits.MI2C1IF = 0; // Clear Master ISR Flag
 IFS1bits.SI2C1IF = 0; // Clear Slave ISR Flag
 IEC1bits.MI2C1IE = 1; // Enable Master Interrupts
 IEC1bits.SI2C1IE = 1; // Enable Slave Interrupts
        INTCON2bits.GIE = 1; // Global Interrup Enable

 I2C1CONbits.I2CEN = 1; // Enable the I2C

 /*
  * Pin RB2 is our EEPROM Trigger. trigger read with positive edge
  */
  TRISBbits.TRISB2 = 0;
 LATBbits.LATB2 = 0;

 for (delay = 0; delay < 0x1fffff; delay++) {
  Nop();
 }

 LATBbits.LATB2 = 1;  // Trigger EEPROM Read

 while(1) {
  Nop();
 }
 return(0);
}

#1

9 Replies Related Threads

    Mysil
    Super Member
    • Total Posts : 4130
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/16 16:34:37 (permalink)
    0
    Hi,
     
    What value do you have in I2C1ADD  register?
    I2C peripheral hardware will Not react and interrupt the CPU, unless address called from Master match with what Slave have been set to respond to.
     
    Note, that the first 8, and last 8 addresses are reserved for special purposes,
    so valid addresses for ordinary slave devices, are from 8 thru 119.
     
        Mysil
     
    #2
    arigead
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2011/02/07 06:58:31
    • Location: 0
    • Status: offline
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/17 12:44:08 (permalink)
    0
    Thank you, should have put that explicitly in the code. I'm using an address of 0x00, which is the reset value of that register, but I added that explicitly to the code, which made no difference. Either way address 0x00 gives no reset. Unfortunately the board I have as hard coded the address as zero. Is 0x00 a valid I2C Address, I've never seen that its not, so assumed it was a valid slave address?
    #3
    arigead
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2011/02/07 06:58:31
    • Location: 0
    • Status: offline
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/18 12:26:55 (permalink)
    0
    I've changed my address to 0x50 which appears to be the correct address for the EEPROM chip, according to the logic analyser. I tried to upload a screenshot of the logic analyser but can't see it on this thread.
     
    From the I2C reference: https://ww1.microchip.com/downloads/en/DeviceDoc/70000195g.pdf
     
    "The I2CxADD register holds the slave device address. In 10-Bit Addressing mode, all bits arerelevant. In 7-Bit Addressing mode, only the I2CxADD<6:0> bits are relevant. TheI2CxADD<6:0> bits correspond to the upper 7 bits in the address byte. The Read/Write bit (R/W)is not included in the value in this register"
     
    So I've got the right address 0x50 in I2C1ADD but still no interrupt when it that address is received on the I2C lines. Just can't see the issue. I2C is 7 bit addressing by default
    #4
    arigead
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2011/02/07 06:58:31
    • Location: 0
    • Status: offline
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/18 12:45:50 (permalink)
    0
     
    Tried 0xa0, the bit shifted up version but no difference, no ISRs
    #5
    arigead
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2011/02/07 06:58:31
    • Location: 0
    • Status: offline
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/18 13:53:09 (permalink)
    0
    Wrote a program to step through the address range and have the master device try and read from the I2C bus. No ISR is generated for any 7 bit address 0x00 to 0xff.
     
    Does the dsPIC33EP256GP502 have a functioning I2C peripheral?
     
    #6
    arigead
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2011/02/07 06:58:31
    • Location: 0
    • Status: offline
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/20 04:49:26 (permalink)
    0
    I changed the code to make use of the I2C Address Mask. Setting it to "Could not care less" about address, (0xffff) means that any activity should trigger an interrupt. Buzzed out the circuit to check that the pins are actually connected as they should be and yes everything is in order. So pins connected, Output pin working on the logic analyser, address mask set to don't care, Interrupts enabled and never got an interrupt.
     
    Does slave mode I2C actually work on a dsPIC33? Think I'll bit bang this protocol, for the moment, as it'll be easier then enabling the dsPIC33 I2C Peripheral.
     
     
     
    #include <xc.h>

    void __attribute__((__interrupt__, __no_auto_psv__)) _MI2C1Interrupt(void)
    {
        LATBbits.LATB13 = 0;
        while(1) {
            Nop();
        }
    }

    void __attribute__((__interrupt__, __no_auto_psv__)) _SI2C1Interrupt(void)
    {
        LATBbits.LATB13 = 0;
        while(1) {
            Nop();
        }
    }

    int main(void)
    {
        uint32_t  delay;

        /*
         * LED Pin
         */
        ANSELAbits.ANSA0 = 0;      // Digital pin
        TRISAbits.TRISA0 = 0;
        LATAbits.LATA0   = 0;      // LED Off;

        /*
         * Set out watch pin high
         */
        TRISBbits.TRISB13 = 0;
        LATBbits.LATB13 = 1;

        /*
         * Pin RB8 is Clock, set input/Open Drain
         */
        ANSELBbits.ANSB8 = 0;       // Digital Mode
        ODCBbits.ODCB8   = 1;
         TRISBbits.TRISB8 = 1;

        /*
         * Pin RB9 is out Data pin SDA, Set input/Open Drain
         */
        ODCBbits.ODCB9   = 1;
        TRISBbits.TRISB9 = 1;

        /*
         * Enable I2C1 Interrupts
         */
        IFS1bits.MI2C1IF     = 0;       // Clear Master ISR Flag
        IFS1bits.SI2C1IF     = 0;       // Clear Slave ISR Flag
        IEC1bits.MI2C1IE     = 1;       // Enable Master Interrupts
        IEC1bits.SI2C1IE     = 1;       // Enable Slave Interrupts
            INTCON2bits.GIE      = 1;       // Global Interrupt Enable

        I2C1ADD              = 0x00;    // I2C Address
        I2C1MSK              = 0xffff;  // Mask could NOT care less

        I2C1CONbits.I2CEN    = 1;       // Enable the I2C

        /*
         * Pin RB2 is our EEPROM Trigger. Positive edge initiates EEPROM Read
         */
         TRISBbits.TRISB2 = 0;

        while(1) {
            LATBbits.LATB2   = 0;

            for (delay = 0; delay < 0x01ffff; delay++) {
                Nop();
            }

            LATBbits.LATB2  = 1;

            for (delay = 0; delay < 0x01ffff; delay++) {
                Nop();
            }
            I2C1CONbits.I2CEN = 0;            // Disable the I2C
            I2C1ADD           = I2C1ADD + 1;
            I2C1CONbits.I2CEN = 1;            // Enable the I2C

            if(I2C1ADD & 0xff == 0xff) {
                LATAbits.LATA0 = 1;      // LED On;
            }
        }
        return(0);
    }
    #7
    ric
    Super Member
    • Total Posts : 30223
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/20 05:04:50 (permalink)
    0
    Are the I2C pins analog capable?
    If yes, it's your job to switch them 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!
    #8
    arigead
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2011/02/07 06:58:31
    • Location: 0
    • Status: offline
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/22 12:46:10 (permalink)
    0
    Of the two I2C Pins being used RB8 and RB9 only RB8 is analog capable. That's been set to digital with the line:
     
    ANSELBbits.ANSB8 = 0;       // Digital Mode
    #9
    arigead
    Super Member
    • Total Posts : 455
    • Reward points : 0
    • Joined: 2011/02/07 06:58:31
    • Location: 0
    • Status: offline
    Re: dsPIC33EP256GP502 Enabling I2C_1 Slave ISR? 2021/02/25 14:35:28 (permalink)
    0
    So I got a bit bang implementation of I2C slave protocol working, but never got an Interrupt from the dsPIC33EP256GP502 with I2C activity. I just don't think slave I2C operation works at all, and given the lack of response it's not something that's used by many people.
    #10
    Jump to:
    © 2021 APG vNext Commercial Version 4.5