EmbeddedRelated.com
Forums

Interprocesser I2C communication problem

Started by Dhananjay July 26, 2005
 
Hi all,
 
    I am doing the interprocesser communication using the I2C communication.Atr my master side the The RCM3000 processer while slave is the 16F873A.THe problem is that my communication is fine from the one side. When I am taking the data from the slave it given me the desired data.But I am sending some the data it is not received by the slave.
    I am using the same library function given by the DC.I am asking the error code it give me the error code 0. THis mean that the communication is occured. But the data is not actual received by slave caz I am toggling a pin. But it not happing. While I am asking some data from slave. IT gives me the desired data.
    THe library code is as follows.
Please go through it code suggest me any error
 
This is Master transmit From Rabbit(Master) to PIC(Slave).
int send_command(unsigned char slave,unsigned char buf)
{
 auto unsigned char cnt;
 auto short int err;
   if (err=i2c_startw_tx())
  {
      i2c_stop_tx();
      return -10+err; // Return too long stretching
  }
   if(err=i2c_wr_wait(slave))
   {
       i2c_stop_tx();
       return -20+err; // Return no ack on slave (retried)
   }
    
if(err=i2c_write_char(buf)
   {
       i2c_stop_tx();
       return -30+err;
    }
    i2c_stop_tx();
    return 0;
}
 
This is Master Receive 
int get_data(unsigned char slave,unsigned char *buf)
{
     auto unsigned char cnt;
     auto short int err;
 
     if (err=i2c_startw_tx())
     {
           i2c_stop_tx();
          return -10+err; // Return too long stretching
     }
     if(err=i2c_wr_wait(slave))
      {
           i2c_stop_tx();
           return -20+err; // Return no ack on slave
      }
     if (err=i2c_startw_tx())
     {
       i2c_stop_tx();
        return -30+err; // Return too long stretch on read
     }
       if (err=i2c_wr_wait(slave+1))
      {
          i2c_stop_tx();
          return -40+err; // Send read to slave - no ack (retried) return -5
      }
     err=i2c_read_char(buf);
     if (err)
    {
        i2c_stop_tx();
        return -50+err;
    }
 
   i2c_send_nak();
   i2c_stop_tx();
 return 0;
}
 
 

Warm Regards,
 
Dhananjay
Embedded System Engineer
TPT india Pvt. Ltd.
3.2,Herekar park, near Kamla Nehru park,
Bhandarkar road, Pune:-411004
India.
PhNo:-+91-020-25660665
MobileNo:-+91-9890396394
Email :- D...@touchplate.com
Website. www.touchplate.com


Why do you think the problem is on the Rabbit side? I
would suspect the PIC first. The PIC has a bug in its
I2C peripheral that you have to account for. There is
an app note on Microchip's web site that addresses
this issue as well as some sample code for using a PIC
as an I2C slave device. Have you read these?

--- Dhananjay <dsalve@dsal...> wrote:

>
> Hi all,
>
> I am doing the interprocesser communication
> using the I2C communication.Atr my master side the
> The RCM3000 processer while slave is the 16F873A.THe
> problem is that my communication is fine from the
> one side. When I am taking the data from the slave
> it given me the desired data.But I am sending some
> the data it is not received by the slave.
> I am using the same library function given by
> the DC.I am asking the error code it give me the
> error code 0. THis mean that the communication is
> occured. But the data is not actual received by
> slave caz I am toggling a pin. But it not happing.
> While I am asking some data from slave. IT gives me
> the desired data.
> THe library code is as follows.
> Please go through it code suggest me any error
>
> This is Master transmit From Rabbit(Master) to
> PIC(Slave).
> int send_command(unsigned char slave,unsigned char
> buf)
> {
> auto unsigned char cnt;
> auto short int err;
> if (err=i2c_startw_tx())
> {
> i2c_stop_tx();
> return -10+err; // Return too long stretching
> }
> if(err=i2c_wr_wait(slave))
> {
> i2c_stop_tx();
> return -20+err; // Return no ack on slave
> (retried)
> }
> if(err=i2c_write_char(buf)
> {
> i2c_stop_tx();
> return -30+err;
> }
> i2c_stop_tx();
> return 0;
> }
>
> This is Master Receive
> int get_data(unsigned char slave,unsigned char *buf)
> {
> auto unsigned char cnt;
> auto short int err;
>
> if (err=i2c_startw_tx())
> {
> i2c_stop_tx();
> return -10+err; // Return too long
> stretching
> }
> if(err=i2c_wr_wait(slave))
> {
> i2c_stop_tx();
> return -20+err; // Return no ack on slave
> }
> if (err=i2c_startw_tx())
> {
> i2c_stop_tx();
> return -30+err; // Return too long stretch
> on read
> }
> if (err=i2c_wr_wait(slave+1))
> {
> i2c_stop_tx();
> return -40+err; // Send read to slave - no
> ack (retried) return -5
> }
> err=i2c_read_char(buf);
> if (err)
> {
> i2c_stop_tx();
> return -50+err;
> }
>
> i2c_send_nak();
> i2c_stop_tx();
> return 0;
> } > Warm Regards,
>
> Dhananjay
> Embedded System Engineer
> TPT india Pvt. Ltd.
> 3.2,Herekar park, near Kamla Nehru park,
> Bhandarkar road, Pune:-411004
> India.
> PhNo:-+91-020-25660665
> MobileNo:-+91-9890396394
> Email :- Dsalve@Dsal...
> Website. www.touchplate.com> No virus found in this
outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.338 / Virus Database: 267.9.5/58 -
> Release Date: 7/25/2005
>




Will you please send me the link. Thus i can refer the Application
note

Dhananjay
--- In rabbit-semi@rabb..., Steve Trigero <seecwriter@y...>
wrote:
> Why do you think the problem is on the Rabbit side? I
> would suspect the PIC first. The PIC has a bug in its
> I2C peripheral that you have to account for. There is
> an app note on Microchip's web site that addresses
> this issue as well as some sample code for using a PIC
> as an I2C slave device. Have you read these?
>
> --- Dhananjay <dsalve@t...> wrote:
>
> >
> > Hi all,
> >
> > I am doing the interprocesser communication
> > using the I2C communication.Atr my master side the
> > The RCM3000 processer while slave is the 16F873A.THe
> > problem is that my communication is fine from the
> > one side. When I am taking the data from the slave
> > it given me the desired data.But I am sending some
> > the data it is not received by the slave.
> > I am using the same library function given by
> > the DC.I am asking the error code it give me the
> > error code 0. THis mean that the communication is
> > occured. But the data is not actual received by
> > slave caz I am toggling a pin. But it not happing.
> > While I am asking some data from slave. IT gives me
> > the desired data.
> > THe library code is as follows.
> > Please go through it code suggest me any error
> >
> > This is Master transmit From Rabbit(Master) to
> > PIC(Slave).
> > int send_command(unsigned char slave,unsigned char
> > buf)
> > {
> > auto unsigned char cnt;
> > auto short int err;
> > if (err=i2c_startw_tx())
> > {
> > i2c_stop_tx();
> > return -10+err; // Return too long stretching
> > }
> > if(err=i2c_wr_wait(slave))
> > {
> > i2c_stop_tx();
> > return -20+err; // Return no ack on slave
> > (retried)
> > }
> > if(err=i2c_write_char(buf)
> > {
> > i2c_stop_tx();
> > return -30+err;
> > }
> > i2c_stop_tx();
> > return 0;
> > }
> >
> > This is Master Receive
> > int get_data(unsigned char slave,unsigned char *buf)
> > {
> > auto unsigned char cnt;
> > auto short int err;
> >
> > if (err=i2c_startw_tx())
> > {
> > i2c_stop_tx();
> > return -10+err; // Return too long
> > stretching
> > }
> > if(err=i2c_wr_wait(slave))
> > {
> > i2c_stop_tx();
> > return -20+err; // Return no ack on slave
> > }
> > if (err=i2c_startw_tx())
> > {
> > i2c_stop_tx();
> > return -30+err; // Return too long stretch
> > on read
> > }
> > if (err=i2c_wr_wait(slave+1))
> > {
> > i2c_stop_tx();
> > return -40+err; // Send read to slave - no
> > ack (retried) return -5
> > }
> > err=i2c_read_char(buf);
> > if (err)
> > {
> > i2c_stop_tx();
> > return -50+err;
> > }
> >
> > i2c_send_nak();
> > i2c_stop_tx();
> > return 0;
> > }
> >
> >
> > Warm Regards,
> >
> > Dhananjay
> > Embedded System Engineer
> > TPT india Pvt. Ltd.
> > 3.2,Herekar park, near Kamla Nehru park,
> > Bhandarkar road, Pune:-411004
> > India.
> > PhNo:-+91-020-25660665
> > MobileNo:-+91-9890396394
> > Email :- Dsalve@t...
> > Website. www.touchplate.com> No virus found in this
> outgoing message.
> > Checked by AVG Anti-Virus.
> > Version: 7.0.338 / Virus Database: 267.9.5/58 -
> > Release Date: 7/25/2005
> >