CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

I2C almost running

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rudy



Joined: 27 Apr 2008
Posts: 168

View user's profile Send private message Send e-mail MSN Messenger

I2C almost running
PostPosted: Sat Feb 20, 2010 6:25 pm     Reply with quote

Hi everybody, I need a little help to finalize my I2C routine. The problem happens when I try to read the slave, the master receive all bytes, but the slave keeps waiting ACK after the last transmitted byte. How do I solve this?

MASTER ASKS:
Code:

void i2c_rx(address)
   {
   deb=1;
    i2c_start();
                i2c_write(address+1);                     
                data0=i2c_read();
                data1=i2c_read();
                data2=i2c_read();
                data3=i2c_read();
                data4=i2c_read(0);
                i2c_stop();
                }

SLAVE ANSWERS:
Code:

#INT_SSP
void SSP_isr()
     { 
     if(sspstat_rw==1)  //BACK TO MASTER TRANSMITER
        {
         i2c_write(0);
         i2c_stop();
         i2c_write(1);
         i2c_stop();
         i2c_write(2);
         i2c_stop();
         i2c_write(3);
         i2c_stop();
         i2c_write(4);
         }
    else
        {       
        if(sspstat_da==1)  //RECEIVED DATA
             {
              aux_rx++;
              buffer_rx[aux_rx]=i2c_read();                   
              if(aux_rx==0x04)flag_0=1;
              }
        else
             {
              address=i2c_read(); //ADDRESS RECEIVE
              aux_rx=0xff;
              }
         }
   }   
 

Works really fine, the problem is that, when RW=1, the master receives all data, but no ACK is returned. The BUS stay locked.

Please help me.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 21, 2010 2:13 pm     Reply with quote

This post has sample i2c code that reads multiple bytes:
http://www.ccsinfo.com/forum/viewtopic.php?t=39565&start=4
rudy



Joined: 27 Apr 2008
Posts: 168

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sun Feb 21, 2010 6:08 pm     Reply with quote

Thanks Sr.

I already solved the problem.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group