Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

[SOLVED] Spurious scl transition error in pic18f6722 i2c code

Status
Not open for further replies.

Logu KS

Member level 2
Joined
Jul 19, 2014
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Chennai
Activity points
372
Code:
/* I2C */

/* Header file */

#include<pic18.h>
#include<TIMER.h>
#define _XTAL_FREQ 4E6

void I2Cinit(void);
void I2Cstart(void);
void I2Cstart(void);
void I2Cstop(void);
void I2CsendACK(void);
void I2CsendNACK(void);
void I2Cwait(void);
void I2Csend(unsigned char dat);
bit I2Cwritebyte(unsigned char dat);
unsigned char I2Creadbyte(unsigned char ack);

/* I2C Functions */

void I2Cinit(void)
{	
	TRISC3 = 1;					// SCK as input
	TRISC4 = 1;					// SDA as input
	SSP1STAT |= 0x80;			// Slew rate control enable for high speed mode for standard speed
	SSP1CON1 = 0x38;				// I2C master mode and SCK and SDA as serial pins
	SSP1CON2 = 0x00;
	SSP1ADD = 9;
}

void I2Cstart(void)
{
	I2Cwait();
	SEN = 1;					// Start enable bit
	//SSPCON2 bit 0
	while (SEN == 1);
}

void I2Crestart(void)
{
	I2Cwait();
	RSEN = 1;					// Restart enable bit
	//SSPCON2 bit 1
	while (RSEN == 1);
}

void I2Cstop(void)
{
	I2Cwait();
	PEN=1;						// Stop enable bit
	while(PEN==1);
	//continue;
}

void I2CsendACK(void)
{
	ACKDT = 0;					// 0 = ACK
	ACKEN = 1;					// Sending ack
	while(ACKEN);
}

void I2CsendNACK(void)
{
	ACKDT = 1;					// 1 = NACK
	ACKEN = 1;					// Sending nack
	while(ACKEN);
}

void I2Cwait(void)
{
	while ( ( SSP1CON2 & 0x1F ) || ( SSP1STAT & 0x04 ) );
}

void I2Csend(unsigned char dat)
{
	SSP1BUF = dat; 
    while(BF);      
    I2Cwait();      
}

bit I2Cwritebyte(unsigned char dat)
{
	SSP1BUF = dat;    
    while(BF);      
	return 0;
    //I2Cwait();      
}

unsigned char I2Creadbyte(unsigned char ack)
{
 	unsigned char temp;
 	I2Cwait();
 	RCEN=1;
 	I2Cwait();
 	temp = SSP1BUF;
 	I2Cwait();
 	if (ack)ACKDT=0;
 	else ACKDT=1;
 	ACKEN=1; 
 	return( temp );
}

/* Main */

void main()
{
	I2Cinit();
	I2Cstart();
	I2Csend('M');
	I2CsendACK();
	I2Cstop();
	while(1)
	{}
}

this is my i2c code while compiling there is no error and warning in mplab ide

when i put it in proteus it is showing spurious scl transition detected...
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
You can try setting TRISC3 and TRISC4 as outputs. Also you can use I2C_wait() between each I2C function called.
 

Logu KS

Member level 2
Joined
Jul 19, 2014
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Chennai
Activity points
372
i tried by using I2C_wait function in between the function calls....

but same thing is happening in the proteus
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Zip and post your complete MPLAB 8 project files. Which version of Hi-Tech C Compiler are you using ?
 

Logu KS

Member level 2
Joined
Jul 19, 2014
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Chennai
Activity points
372
i am using hightech c pro for the PIC18 family v9.65 and MPLAB v.8.56

- - - Updated - - -

I also tried the i2c.h peripheral library file. While using it there is an error....

Error [499] ; 0. undefined symbol:
_putsI2C1(I2C.obj)
 

Attachments

  • I2C.zip
    112.2 KB · Views: 3

Logu KS

Member level 2
Joined
Jul 19, 2014
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Chennai
Activity points
372
The problem is solved in mplabx ide and xc8 compiler.....
While compiling the code in xc8 compilere there are no spurious transition errors in proteus..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top