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 support@ccsinfo.com

Will this work ?? (While loop related)

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



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Will this work ?? (While loop related)
PostPosted: Thu Oct 21, 2010 3:11 pm     Reply with quote

Hi Guys, Can really test this code because I am @ home, only in the lab tomorrow. Just wondering if the while would cause inf loop. I am sending about 50 commands like this one
Code:
write(OV5620_WRITE_ADDR, 0x12, 0x80);
But instead of adding a delay after the i2c stop i would rather check to see whether the device is still busy. ANy tips or comments ?


Code:
int8 write(int8 cmd1,int8 cmd2,int8 cmd3)
    {
        while(!camera_ready());
        {
        i2c_start();
        i2c_write(int8 cmd1);
        i2c_write(int8 cmd2);
        i2c_write(int8 cmd3);
        i2c_stop();
        }
    }


Code:
int1 camera_ready()
 {
   int1 ack;
   i2c_start();            // If the write command is acknowledged,
   ack = i2c_write(0x60);  // then the device is ready.
   i2c_stop();
   return !ack; 
}


Thanks.
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 21, 2010 3:27 pm     Reply with quote

What if your i2c slave device is detached or defective ? You'll never get
an ACK in that case. Then how do you ever get out of the loop ? Maybe
a WDT reset ? Or, add a timeout count and return an error code if it
times out.
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