I2C protocol debbugging

Status
Not open for further replies.

thunaivendan

Member level 3
Joined
Apr 19, 2013
Messages
61
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,288
Location
Chennai, Tamil Nadu, India
Activity points
1,726
Hi guys,

I finished a code for I2C..when i stimulated in proteus..i2c debugger shows error message is "DATA written in SSPBUF whilst MSSP(i2c in matermode) data has been ignored"

But written data shown in i2c debbugger..here i attached images..
and written data is 0x05 in debbugger viewed as 0x50..
and if send a string how it's possible...

 
Last edited by a moderator:

I think storing of bits in the address is the problem.. check whether MSB or LSB is receiving first.
 

Can you post your code plz
 

I think storing of bits in the address is the problem.. check whether MSB or LSB is receiving first.

hi guys
my data is 0x05
when i seen in debugger 0x50...i doubt with,whether data is written or not...
below this routine for main()

Code:
void main()
{
 TRISE=0;
 PORTE=0;
 TRISD=0;   
 PORTD=0;
 TRISC=0xff;
 PORTC=0;
 ADCON1=0x06;
 lcd_init();
 i2c_init();
 i2c_start();
 i2c_address(0xa0,0);
// i2c_ack();
 i2c_restart();
 i2c_address(0xa0,0);
 //i2c_ack();
 i2c_address(0x00,0);
 i2c_ack();
 i2c_write(0x05);
 //i2c_ack();
 i2c_stop();
 i2c_ack();
// i2c_wait();
 i2c_start();
 i2c_address(0xa0,1);
 i2c_restart();
 i2c_address(0xa0,1);
 //i2c_read(0);
 
 *value=i2c_read(1);
 disp_data((value));
 //delay_ms(10);    
}
:???::???::???:
 
Last edited by a moderator:


You must share the code for i2c_init,i2c_address and read the error may be in the configurations and also include a delay of 50 - 100 ms in between i2c_read and disp_data.
 
Last edited by a moderator:

You must share the code for i2c_init,i2c_address and read the error may be in the configurations and also include a delay of 50 - 100 ms in between i2c_read and disp_data.

kindly debbugg it soon,,,,,
Code:
void i2c_init()//I2C intialize Function
{
TRISC3=1;
TRISC4=1;
SSPSTAT=0x80;
SSPCON=0x28;
//SSPCON2=0x00;
SSPADD=(((_XTAL_FREQ/4)/i2c_speed)-1);
}
void i2c_start()//I2C Strart Function
{     i2c_wait();
      SEN = 1;         /* Start condition enabled */
        while(SEN);    /* automatically cleared by hardware */
                       /* wait for start condition to finish */
}
void i2c_stop()//I2C Stop Function
{ 
   i2c_wait(); 
    PEN = 1;         /* Stop condition enabled */
        while(PEN);  /* Wait for stop condition to finish */
                     /* PEN automatically cleared by hardware */

}
void i2c_restart()
{  i2c_wait(); 
   RSEN=1;
   while(RSEN);
}
void i2c_ack()
{
  ACKDT=0;ACKEN=1;
  while(ACKEN);
  
}
void i2c_nack()
{
  ACKDT=1;ACKEN=1;while(ACKEN);
 
}
void i2c_write(unsigned char data)
{  SSPIF=0;
   SSPBUF=data;
   while(!SSPIF);     
   i2c_ack();
}
void i2c_address(unsigned char address, unsigned char mode)
{
    unsigned char l_address;
    l_address=address|mode;
    //l_address+=mode;
    i2c_wait();
    SSPBUF = l_address;
}
unsigned char i2c_read(unsigned char ack)
{
    // Read data from slave
    // ack should be 1 if there is going to be more data read
    // ack should be 0 if this is the last byte of data read
    unsigned char i2c_read_data;

    i2c_wait();
    RCEN=1;
    while(RCEN);
    while(!BF); 
    i2c_wait();
    if ( ack ) ACKDT=0;	        // Ack
    else       ACKDT=1;	        // NAck
    ACKEN=1;                    // send acknowledge sequence
   // i2c_read_data = SSPBUF;
    //i2c_wait();
    return(SSPBUF);
}

void i2c_wait()
{
 while ( ( SSPCON2 & 0x1F ) || ( SSPSTAT & 0x04 ) );
}
 
Last edited by a moderator:


which is your i2c slave device? Is it an eeprom?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…