Continue to Site

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.

I2C help urgent - program stuck in start condition

Status
Not open for further replies.

omairrk

Newbie level 4
Joined
Jun 2, 2009
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,323
sspif pic

Hi Everyone,

I am using CCS compiler and PIC simulator IDE for interfacing PIC16F877 and EEPROM.

I got the results using built n functions of CCS. But when I am using it without built in functions the program stuck in start condition. Actually hardware is not clearing SEN bit.

Can anybody indicate the problem. Many thanks.

Regards,
Mork.
 

omairrk

Hi,

Your I2c init routine should be like the following

void i2c_init()
{
TRISC3=1;
TRISC4=1;
SSPCON=0x28;
SSPADD=(FOSC / (4 * BAUD)) - 1;
SSPSTAT=80;
}

Just Set the SEN bit.. and wait for bit SSPIF to be set.

SEN=1;
while(!SSPIF); SSPIF=0;

Thats all,
This is Hardware I2C not software.
 

Re: I2C Help Urgent

Hi,

Well I am simulating the code using PIC simulator IDE. My code is exactly similar to that you have posted. SCL and SDA always stay high and sspif always remain low.

The same code using built in functions is working perfectly but the code that involves my own functions get stuck in the first routine of Start Condition.

Here is my code using CCS..


void i2c_int()
{
trisc3=1;
trisc4=1;

SSPCON2=0X80;
SSPCON=0X38;
SSPADD=0x09;
sspif=0;
bclif=0;
}



void i2c_strt()
{
i2c_idle();
sen=1;
while(sspif==0);
sspif=0;
}
 

I2C Help Urgent

Hi,

No need for this idle state, just comment it and try again and one more thing it is not SSPCON2, it is SSPSTAT register.
 

Re: I2C Help Urgent

Hi,

No man.. its not working.. I think I have to check this code on hardware..
SCL and SDA are never changing there states (always at high logic)..

Here is my code:

void i2c_int()
{
trisc3=1;
trisc4=1;
SSPCON2=0X00;
SSPCON=0X38;
SSPADD=0x09;
SSPSTAT=0X80;
sspif=0;
bclif=0;

}

void i2c_strt()
{
//i2c_idle();
sen=1;
while(sspif==0);
sspif=0;
}
 

I2C Help Urgent

hi

i made a I2C aquisition central the other day with a 18f452 and C18 and it work very well.

look my I2C init routine :

void i2c_init(void)
{
DDRCbits.RC3 = 1; // SCL (PORTC,3) en entrée
DDRCbits.RC4 = 1; // SDA (PORTC,4) en entrée

SSPSTAT = 0x80; // Slew rate control disabled for Standard Speed mode (100 kHz and 1 MHz)
SSPCON1= 0x28; // WCOL SSPOV SSPEN CKP SSPM3:SSPM0
// efface WCOL et SSPOV, active I2C, I2C mode maitre horloge=FOSC/(4*(SSPADD+1))
//SSPSTATbits.SMP=1;
//SSPADD = 0x31; // ((20Mhz/100k)/4)-1=49 for 100k operation
SSPADD = (unsigned char)(49);
SSPCON2 = 0x00; // Clear MSSP Conrol Bits
}
 

Re: I2C Help Urgent

Hi microtoad,

Well actually i am using CCS compiler and PIC simulator for PIC-EEPROM interface...
I have done it successfully using built in functions of CCS. But i when i am compiling my own functions they are not working.. there is no difference between my and your code except that of syntax as you are using MPlab. May be i am missing any fuse to add.. but i am unable fixing it..

The problem exists at the beginning of the start condition.. sspif flag never rolls to high logic thats why the loop get stuck at:

sen=1;
while(sspif==0); --get stuck here

This is because the SDA and SCL are never changing there states...
 

I2C Help Urgent

Hi,

Put ur code first and let me analyze
 

Re: I2C Help Urgent

Hi,

I have tried a very shorter version of the code as the program gets stuck in the start condition so i have written only two routines.

#define sda portc4
#define scl portc3

void main(void)
{
trisc3=1;
trisc4=1;
SSPCON2=0X00; //initialize
SSPCON=0X38;
SSPADD=0x09;
SSPSTAT=0X80;
sspif=0;
bclif=0;

sen=1; //start condition
while(sspif==0); sspif never sets to high, program stuck here.
sspif=0;
}

During simulation i noted that sda and scl never changing states (always active high).. So i guess the i2c module is not activating.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top