• AVR Freaks

DSPIC33FJ64GS606 I2C SLAVE

Author
EricMC2
Engineer
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2020/01/13 09:11:41
  • Location: 0
  • Status: offline
2020/01/22 07:55:58 (permalink)
0

DSPIC33FJ64GS606 I2C SLAVE

Hello,
 have to transfer data in I2C link between a DSPIC33FJ64GS608 (the master) and to DSPIC33FJ64606 (the slave).
I try to use the application note "ce445_i2c_slave" from Microchip . 
My master (a DSPIC33FJ64GS608) send :
1) Start condition
2) 0xA0 : slave address
3) 0x55 : address to write into ramBuffer[256]
4) 0x48 : value to write at 0x55 address
5) Stop condition
 
The slave acknowledge just the two first bytes (0xA0 and 0x55) . But does not acknowledge the 0x48 byte.(Seen with an oscilloscope in I2C protocol)
So, no data writen into ramBuffer[256].
 

struct FlagType
{
    unsigned char AddrFlag : 1;
    unsigned char  DataFlag : 1;
};

unsigned char  ramBuffer[256]; //RAM area which will work as EEPROM for Master I2C device
unsigned char  *ramPtr;        //Pointer to RAM memory locations
struct FlagType flag;

void I2C2_Init( void )
{
    I2C2CONbits.I2CEN=1; //Enables the I2Cx module and configures the SDAx and SCLx pins as serial port pins
    I2C2ADD = 0x50;         // 7-bit I2C slave address must be initialised here.
    IFS3bits.SI2C2IF= 0;    // I2C2 Slave Events Interrupt Flag Status bit
    ramPtr = &ramBuffer[0]; //set the RAM pointer and points to beginning of ramBuffer
    flag.AddrFlag = 0;      //Initlize Addflag
    flag.DataFlag = 0;      //Initlize Dataflag
    IEC3bits.SI2C2IE=1;     // Interrupt request is enabled
}

void __attribute__ ( (interrupt, no_auto_psv) ) _SI2C2Interrupt( void )  // This is the ISR for I2C2 Slave interrupt.
{
    unsigned char   temp;   //used for dummy read
    LATF^=BIT0;
   
    if( (I2C2STATbits.R_W == 0) && (I2C2STATbits.D_A == 0) )    //Address matched
    {
        temp = I2C2RCV;     //dummy read
        flag.AddrFlag = 1;  //next byte will be address
    }
    else if( (I2C2STATbits.R_W == 0) && (I2C2STATbits.D_A == 1) )   //check for data
    {
        if( flag.AddrFlag )
        {
            flag.AddrFlag = 0;
            flag.DataFlag = 1;                      //next byte is data
            ramPtr = ramPtr + I2C1RCV;
        }
        else if( flag.DataFlag )
        {
            *ramPtr = ( unsigned char ) I2C1RCV;    // store data into RAM
            flag.AddrFlag = 0;                      //end of tx
            flag.DataFlag = 0;
            ramPtr = &ramBuffer[0];                 //reset the RAM pointer
        }
    }
    else if( (I2C2STATbits.R_W == 1) && (I2C2STATbits.D_A == 0) )
    {
        temp = I2C2RCV;
        I2C2TRN = *ramPtr;      //Read data from RAM & send data to I2C master device
        I2C2CONbits.SCLREL = 1; //Release SCL1 line
        while( I2C2STATbits.TBF );
        //Wait till all
        ramPtr = &ramBuffer[0]; //reset the RAM pointer
    }
    _SI2C2IF = 0;               //clear I2C2 Slave interrupt flag
}
 
would anyone have an idea of the cause of the problem?
Thanks
#1

0 Replies Related Threads

    Jump to:
    © 2020 APG vNext Commercial Version 4.5