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 problem

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







I2C problem
PostPosted: Fri Jun 19, 2009 9:45 pm     Reply with quote

hi. I am trying to use hardware I2C and it is giving me trouble

Code:
#include<C:\Documents and Settings\Microsoft\My Documents\PIC\project1\I2C ADC\16f886.h>
#include<C:\Documents and Settings\Microsoft\My Documents\PIC\project1\I2C ADC\def_16f886.h>

#fuses intrc_io

#use delay(clock = 1000000)

#use I2C(Force_sW,Master,SDA=PIN_C4,SCL=PIN_C3, slow)

int8 low_buffer = 7;
int8 high_buffer = 8;
int8 config;
int16 adc_in = 9;

void main(void){
   
   osccon = 0x41;
   //Use general call ADC
   i2c_start();
   i2c_write(0x00);//general call
   i2c_write(0x06);//reset command
   i2c_stop();
   //first, configure ADC
      
      i2c_start();
   
      i2c_write(0xD0); //write mode

      //16bit, continuous conversion, PGA = 1V/V
      i2c_write(0x14);
   
      i2c_stop();
   
   while(1){
      i2c_start();
   
      i2c_write(0xD1);//Read mode
   
      delay_ms(10);
      high_buffer = i2c_read();
      delay_ms(10);

      low_buffer = i2c_read();
      delay_ms(10);
      config = i2c_read();
      delay_ms(10);
      i2c_stop();
      high_buffer&=0x7F;
      adc_in = high_buffer;
      adc_in <<= 8;
      adc_in += low_buffer;
   
   
      
      }
   }
      
      

Whenever I put FORCE_HW option instead of force_SW, the program locks up at #use I2c (ie, whenever I halt using debugger, the program is there).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 19, 2009 11:25 pm     Reply with quote

Please don't start multiple threads on the same problem.
Read other posts about common problems when writing an i2c driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=37398
http://www.ccsinfo.com/forum/viewtopic.php?t=35128
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