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

i2c strange output...any ideas

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 07, 2006 4:12 pm     Reply with quote

The problem is that the original poster in that thread never posted
the final working driver. Also, in his driver, he doesn't do a NACK on
the last i2c read. But all sample drivers do this. So I don't think
you can trust his driver.

If I take the sample code for the CMPS03 which Devantech has posted
at this link, http://www.robot-electronics.co.uk/files/example18f452.c
and translate it to CCS, I get the following code:

Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3, FORCE_HW)

void read_compass(int8 *buffer)
{
i2c_start();
i2c_write(0xC0);
i2c_write(0x00);
i2c_start();
i2c_write(0xC1);
buffer[0] = i2c_read();      
buffer[1] = i2c_read();      
buffer[2] = i2c_read();      
buffer[3] = i2c_read(0);
i2c_stop();
}

//============================
void main()
{
int8 compass[4];
int8 version;
int8 bearingB;
int16 bearingW;

while(1)
  {
   read_compass(compass);
   version  = compass[0];
   bearingB = compass[1];
   bearingW = ((int16)compass[2] << 8) + (int16)compass[3];
       
   printf("Version = %u\n\r", version);
   printf("bearingB = %u\n\r", bearingB);
   printf("bearingW = %lu\n\r", bearingW);
   printf("\n\r");
   delay_ms(1000);
  }

}
keplerforever



Joined: 23 Dec 2005
Posts: 8

View user's profile Send private message

PostPosted: Mon May 08, 2006 6:41 am     Reply with quote

great!!!
The code is working perfectly.
Thank you very much, this is a relief for me, since I have always been a bit traumatized with i2c protocol
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