jaethelegend Guest
|
I2C problem |
Posted: Fri Jun 19, 2009 9:45 pm |
|
|
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). |
|