cjusto
Newbie level 3
Hello!
I'm working on a project using:
-MPLAB X IDE V3.00, XC16 Compiler
-MPLAB ICD3 (In-Circuit Debugger)
-dsPIC30F3010
I need this PIC (as a slave) to communicate with a chipkit (as a master), but the I2C interrupt is not happening.
After that I tried to use de Debug function, but with no results.
I am able to program the PIC and it runs, oscillator is ok and some outputs I tested are working fine.
The config used is this:
in the main function this function is called, and it runs fine:
and this is the interrupt function, the one that never worked here:
This code is one of the microchips code examples.
Where I am making something wrong?
Any ideia what I can try out?
Thank You.
I'm working on a project using:
-MPLAB X IDE V3.00, XC16 Compiler
-MPLAB ICD3 (In-Circuit Debugger)
-dsPIC30F3010
I need this PIC (as a slave) to communicate with a chipkit (as a master), but the I2C interrupt is not happening.
After that I tried to use de Debug function, but with no results.
I am able to program the PIC and it runs, oscillator is ok and some outputs I tested are working fine.
The config used is this:
Code:
_FOSC(XT & CSW_FSCM_OFF) ; //_PLL4);
_FWDT(WDT_OFF); // Watchdog Timer Enabled/disabled by user software
_FGS(CODE_PROT_OFF & GWRP_OFF );
_FBORPOR(PWRT_64 & MCLR_EN & PBOR_ON & BORV20);
#define FCY 4000000UL
_FICD (ICS_PGD1);
#include <libpic30.h>
#include <xc.h>
#include<i2c.h>
#include "I2CSlaveDrv.h"
in the main function this function is called, and it runs fine:
Code:
void i2c1_init(void)
{
#if !defined(USE_I2C_Clock_Stretch)
I2CCON = 0x8000; //Enable I2C module
#else
I2CCON = 0x9040; //Enable I2C module, enable clock stretching
#endif
I2CADD = 0x50; // 7-bit I2C slave address must be initialised here.
IFS0=0;
// RAMPtr = &RAMBuffer[0]; //set the RAM pointer and points to beginning of RAMBuffer
Flag.AddrFlag = 0; //Initlize AddFlag
Flag.DataFlag = 0; //Initlize DataFlag
_SI2CIE = 1;
}
and this is the interrupt function, the one that never worked here:
Code:
void __attribute__((interrupt,no_auto_psv)) _SI2CInterrupt (void)
{
unsigned char Temp; //used for dummy read
_RB0 = 1;
if((I2CSTATbits.R_W == 0)&&(I2CSTATbits.D_A == 0)) //Address matched
{
Temp = I2CRCV; //dummy read
Flag.AddrFlag = 1; //next byte will be address
}
else if((I2CSTATbits.R_W == 0)&&(I2CSTATbits.D_A == 1)) //check for data
{
if(Flag.AddrFlag)
{
Flag.AddrFlag = 0;
Flag.DataFlag = 1; //next byte is data
RAMPtr = RAMPtr + I2CRCV;
#if defined(USE_I2C_Clock_Stretch)
I2CCONbits.SCLREL = 1; //Release SCL1 line
#endif
}
else if(Flag.DataFlag)
{
*RAMPtr = (unsigned char)I2CRCV;// store data into RAM
Flag.AddrFlag = 0;//end of tx
Flag.DataFlag = 0;
RAMPtr = &RAMBuffer[0]; //reset the RAM pointer
#if defined(USE_I2C_Clock_Stretch)
I2CCONbits.SCLREL = 1; //Release SCL1 line
#endif
}
}
else if((I2CSTATbits.R_W == 1)&&(I2CSTATbits.D_A == 0))
{
Temp = I2CRCV;
I2CTRN = *RAMPtr; //Read data from RAM & send data to I2C master device
I2CCONbits.SCLREL = 1; //Release SCL1 line
while(I2CSTATbits.TBF);//Wait till all
RAMPtr = &RAMBuffer[0]; //reset the RAM pointer
}
_SI2CIF = 0; //clear I2C1 Slave interrupt flag
}
This code is one of the microchips code examples.
Where I am making something wrong?
Any ideia what I can try out?
Thank You.