jaethelegend Guest
|
I2C routine using MCP3421 ADC |
Posted: Fri Jun 19, 2009 7:54 am |
|
|
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? |
|