Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

showing error for interrupts

Status
Not open for further replies.

vinay shabad

Junior Member level 3
Joined
Dec 13, 2010
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,769
hiiii i am getting error as undeclared sspcon









/***********************************************************************
* Hardware I2C single master routines
* (adapted from application note AN235)
*
* i2c_init - initialize I2C
* i2c_start - issue Start condition
* i2c_repStart - issue Repeated Start condition
* i2c_write - write char - returns ACK
* i2c_read(x) - receive char - x=0, Issue a don't acknowledge (NACK)- x=1, Issue an acknowledge (ACK)
* i2c_stop - issue Stop condition
*
***********************************************************************/
#include <P24F16KA102.h>
#include "i2c.h"


//#include "Compiler.h"

//----------------------------------------------------------------------

void i2c_init(void) {

TRISBbits.TRISB5 = 1; // Digital Output (make it input only when reading data. see spi)
// PORTBbits.RB5 = 1;
TRISBbits.TRISB6 = 1; // Digital Output
// PORTBbits.RB6 = 1;

SSPCON1 = 0x28; // enable I2C Master mode
SSPCON2 = 0x00; // clear control bits
SSPSTAT = 0x80; // disable slew rate control; disable SMBus

SSPADD = 19; // set baud rate to 100 kHz (Fosc = 48 MHz)

PIR1bits.SSPIF = 0;
PIR2bits.BCLIF = 0;

}

//----------------------------------------------------------------------

void i2c_start(void) {

PIR1bits.SSPIF = 0; //clear flag
while (SSPSTATbits.BF ); // wait for idle condition

SSPCON2bits.SEN = 1; // initiate START conditon

while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag
}

//----------------------------------------------------------------------

unsigned char i2c_write( unsigned char i2cWriteData ) {

PIR1bits.SSPIF = 0; // clear interrupt
while ( SSPSTATbits.BF ) ; // wait for idle condition

SSPBUF = i2cWriteData; // Load SSPBUF with i2cWriteData (the value to be transmitted)

while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag

return ( !SSPCON2bits.ACKSTAT ); // function returns '1' if transmission is acknowledged

}

//----------------------------------------------------------------------

unsigned char i2c_read( unsigned char ack ) {

unsigned char i2cReadData;

PIR1bits.SSPIF = 0; // clear interrupt

while ( SSPSTATbits.BF ) ; // wait for idle condition
SSPCON2bits.RCEN = 1; // enable receive mode

while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag

i2cReadData = SSPBUF; // Read SSPBUF and put it in i2cReadData

if ( ack ) { // if ack=1
SSPCON2bits.ACKDT = 0; // then transmit an Acknowledge
} else {
SSPCON2bits.ACKDT = 1; // otherwise transmit a Not Acknowledge
}

SSPCON2bits.ACKEN = 1; // send acknowledge sequence

while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag

return( i2cReadData ); // return the value read from SSPBUF

}

//----------------------------------------------------------------------

void i2c_stop(void) {

PIR1bits.SSPIF = 0; // clear flag
while ( SSPSTATbits.BF ) ; // wait for idle condition

SSPCON2bits.PEN = 1; // Initiate STOP condition

while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag

}

//----------------------------------------------------------------------

void i2c_repStart(void) {

PIR1bits.SSPIF = 0; // clear flag
while ( SSPSTATbits.BF ) ; // wait for idle condition

SSPCON2bits.RSEN = 1; // initiate Repeated START condition

while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag

}

//----------------------------------------------------------------------





error ****************************************





\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c: In function 'i2c_init':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:28: error: 'SSPCON1' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:28: error: (Each undeclared identifier is reported only once
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:28: error: for each function it appears in.)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:29: error: 'SSPCON2' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:30: error: 'SSPSTAT' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:32: error: 'SSPADD' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:34: error: 'PIR1bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:35: error: 'PIR2bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c: In function 'i2c_start':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:43: error: 'PIR1bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:44: error: 'SSPSTATbits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:46: error: 'SSPCON2bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c: In function 'i2c_write':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:56: error: 'PIR1bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:57: error: 'SSPSTATbits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:59: error: 'SSPBUF' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:64: error: 'SSPCON2bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:66: warning: control reaches end of non-void function
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c: In function 'i2c_read':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:74: error: 'PIR1bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:76: error: 'SSPSTATbits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:77: error: 'SSPCON2bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:82: error: 'SSPBUF' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c: In function 'i2c_stop':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:103: error: 'PIR1bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:104: error: 'SSPSTATbits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:106: error: 'SSPCON2bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c: In function 'i2c_repStart':
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:117: error: 'PIR1bits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:118: error: 'SSPSTATbits' undeclared (first use in this function)
C:\Program Files\Microchip\mplabc30\v3.25\support\peripheral_24F\i2c.c:120: error: 'SSPCON2bits' undeclared (first use in this function)
----------------------------------------------------------------------


i am blocked here can some one please helpme



thanku in advanced
 

std_match

Advanced Member level 4
Joined
Jul 9, 2010
Messages
1,187
Helped
444
Reputation
888
Reaction score
409
Trophy points
1,363
Location
Sweden
Activity points
9,155
I think your question is in the wrong section, but it seems that the register names you are using are incompatible with the register names in P24F16KA102.h
 

vinay shabad

Junior Member level 3
Joined
Dec 13, 2010
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,769
Thankyou yes i was using pic 24 nd the intrrupts i was using was for pic 18 .NOw with pic 24F interrupts its working .thanks a lot
 

vinay shabad

Junior Member level 3
Joined
Dec 13, 2010
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,769
for the guys who wants to use i2c with interrupts in pic24 here is my programme
/***********************************************************************
* Hardware I2C single master routines
* (adapted from application note AN235)
*
* i2c_init - initialize I2C
* i2c_start - issue Start condition
* i2c_repStart - issue Repeated Start condition
* i2c_write - write char - returns ACK
* i2c_read(x) - receive char - x=0, Issue a don't acknowledge (NACK)- x=1, Issue an acknowledge (ACK)
* i2c_stop - issue Stop condition
*
***********************************************************************/
#include <P24F16KA102.h>
#include "i2c.h"
//#include "display.h"

//#include "Compiler.h"

//----------------------------------------------------------------------
int main(void)
{
void i2c_init(void) {

TRISBbits.TRISB5 = 1; // Digital Output (make it input only when reading data. see spi)
// PORTBbits.RB5 = 1;
TRISBbits.TRISB6 = 1; // Digital Output
// PORTBbits.RB6 = 1;

I2C1CON = 0x28; // enable I2C Master mode
//I2C1CON2 = 0x00; // clear control bits
I2C1STAT = 0x80; // disable slew rate control; disable SMBus

I2C1ADD = 19; // set baud rate to 100 kHz (Fosc = 48 MHz)

IFS1bits.MI2C1IF = 0;
IEC1bits.MI2C1IE = 0;

}

//----------------------------------------------------------------------

void i2c_start(void) {

IFS1bits.MI2C1IF = 0; //clear flag
while (I2C1STATbits.TBF ); // wait for idle condition

I2C1CONbits.SEN = 1; // initiate START conditon

while (!IFS1bits.MI2C1IF) ; // wait for a flag to be set
IFS1bits.MI2C1IF = 0; // clear flag
}

//----------------------------------------------------------------------

unsigned char i2c_write( unsigned char i2cWriteData,unsigned char RegData ) {

IFS1bits.MI2C1IF = 0; // clear interrupt
while ( I2C1STATbits.TBF ) ; // wait for idle condition

RegData = i2cWriteData; // Load RegData with i2cWriteData (the value to be transmitted)

while (!IFS1bits.MI2C1IF) ; // wait for a flag to be set
IFS1bits.MI2C1IF = 0; // clear flag

return ( !I2C1STATbits.ACKSTAT ); // function returns '1' if transmission is acknowledged

}

//----------------------------------------------------------------------

unsigned char i2c_read( unsigned char ack,unsigned char RegData ) {

unsigned char i2cReadData;

IFS1bits.MI2C1IF = 0; // clear interrupt

while ( I2C1STATbits.TBF ) ; // wait for idle condition
I2C1CONbits.RCEN = 1; // enable receive mode

while (!IFS1bits.MI2C1IF) ; // wait for a flag to be set
IFS1bits.MI2C1IF = 0; // clear flag

i2cReadData = RegData; // Read RegData and put it in i2cReadData

if ( ack ) { // if ack=1
I2C1STATbits.ACKSTAT = 0; // then transmit an Acknowledge
} else {
I2C1STATbits.ACKSTAT = 1; // otherwise transmit a Not Acknowledge
}

I2C1STATbits.ACKSTAT = 1; // send acknowledge sequence

while (!IFS1bits.MI2C1IF) ; // wait for a flag to be set
IFS1bits.MI2C1IF = 0; // clear flag

return( i2cReadData ); // return the value read from SSPBUF

}

//----------------------------------------------------------------------

void i2c_stop(void) {

IFS1bits.MI2C1IF= 0; // clear flag
while ( I2C1STATbits.TBF ) ; // wait for idle condition

I2C1CONbits.PEN = 1; // Initiate STOP condition

while (!IFS1bits.MI2C1IF) ; // wait for a flag to be set
IFS1bits.MI2C1IF = 0; // clear flag

}

//----------------------------------------------------------------------

void i2c_repStart(void) {

IFS1bits.MI2C1IF = 0; // clear flag
while ( I2C1STATbits.TBF ) ; // wait for idle condition

I2C1CONbits.RSEN = 1; // initiate Repeated START condition

while (! IFS1bits.MI2C1IF) ; // wait for a flag to be set
IFS1bits.MI2C1IF = 0; // clear flag

}
}
//----------------------------------------------------------------------
i am not sure that this will clear ur problem but surley will have some help from this programme
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top