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 routine using MCP3421 ADC

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







I2C routine using MCP3421 ADC
PostPosted: Fri Jun 19, 2009 7:54 am     Reply with quote

Hi
I am trying to experiment to see if it is reading the right value.
since it is first time I am trying to use I2C built in CCS function
I may have made mistake.


below is the coding I wrote

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(Master,SDA = PIN_C4, SCL = PIN_C3)

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

void main(void){
   
   osccon = 0x41;
   
   //first, configure ADC
      i2c_start();
     
      i2c_write(0xD0); //write mode

      //16bit, continuous conversion, PGA = 1V/V
      i2c_write(0x1C);
   
      i2c_stop();
   
   while(1){
      i2c_start();
      i2c_write(0xD1);//Read mode

     
      high_buffer = i2c_read();
   

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

No matter what value of input voltage I put in to ADC, it returns 0xFF when I use I2c_read.

Can anybody figure it 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