View previous topic :: View next topic |
Author |
Message |
eastvoltresearch
Joined: 02 Apr 2004 Posts: 3
|
MAX127 and I2C |
Posted: Sat Apr 03, 2004 7:31 pm |
|
|
Anyone else here have experience with accessing the MAX127 A/D Converter via I2C. I'm about ready to throw this damn thing out the window. Can't get it to talk correctly with my PIC16C76 via I2C.
Have no problems with other i2C devices, just this one.
Dan |
|
|
gyork Guest
|
MAX127 and I2C |
Posted: Sun Apr 04, 2004 7:30 pm |
|
|
This is code I used to figure out the MAX128 wich is similar to the 127.
Hope it helps
void main() {
int16 atod,result;
int8 result1,result2,i;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
printf("initiating max128\r\n");
//setup i2c
output_float(PIN_C3);
output_float(PIN_C4);
while (1){
//setup max128 to read channel 0
i2c_start();
i2c_write(0b01010000); //channel 0 0 to 4096 mV
i2c_write(0xF8); // send configuration bit
i2c_stop(); // start conversion
//read result from max128
i2c_start();
i2c_write(0b01010001); // send address to chip to begin read
result1 = i2c_read(); // get high byte of 12bit result
result2 = i2c_read(0);
i2c_stop(); // get low nibble of 12bit result
//convert to 16bit result
result = result1;
result = (result << 4 )+ (result2 >> 4); // combine into 16 bit result first four bits are 0s
printf("%ld\r\n",result); //debug
delay_ms(250);
}
} |
|
|
eastvoltresearch
Joined: 02 Apr 2004 Posts: 3
|
|
Posted: Sun Apr 04, 2004 8:24 pm |
|
|
Thanks for the code. I actually did figure out my problem after about 3 hours of scoping the waveforms etc...
Turns out i had a very stupid error. On one of my i2c_write commands, I had a an address marked 0x01010000 instead of 0b0101000.
Figures it would be something stupid.
dan |
|
|
AK Guest
|
|
Posted: Sat Apr 10, 2004 8:59 am |
|
|
I am also starting a project and I would like to use the MAX127. How has this chip worked for you so far. Any problems? Could you post sample code for communicating with the chip? |
|
|
MIGHTymouse Guest
|
similar problem |
Posted: Fri Apr 13, 2007 6:32 am |
|
|
Hi!
I'm also (trying) to connect a 16f876a to a max127.
I usel a code similar to yours
Code: |
void initI2C(){
output_float(SCL_C3);
output_float(SDA_C4);
}
void writeI2C(INT16 comand){
i2c_start(); // Start condition
i2c_write(add_ADC); // Address
i2c_write(comand); // send configuration bit
i2c_stop(); // Stop condition
}
INT16 readI2C(){
BYTE b1=0, b2=0;
i2c_start(); // "restart" condition
i2c_write((end_ADC | 0x01)); // address + R/W
b1 = i2c_read(1); // read 1ºbyte
b2 = i2c_read(0); // read 2ºbyte
i2c_stop(); // Stop condition
return make16(b2, b1);
}
int16 getdata(){
unsigned int16 value;
unsigned int16 comando=0x80; //0xf8 //08 ou 80
valor=0;
writeI2C(comand);
delay_us(8);
value=readI2C();
return value;
}
|
But although i'm communicating (or at least it doesn's blocks), i'm not reading nothing but '1's. (65535).
Is it supposed to define the frequency or something?
is there a way to assure the max 127 is functioning right? |
|
|
David Moussa Guest
|
MAX127 and I2C |
Posted: Thu Oct 08, 2009 7:56 pm |
|
|
I'm also trying to use a MAX127 but the problem is I'm just reading
0s from the max127 regardless of the voltage level on the channels.
Is there something significant about this 0 or is it not working at all
cheers |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 08, 2009 8:32 pm |
|
|
Post a complete test program. It should have the #include for the PIC,
#fuses, #use delay() and #use i2c() statements. It should have a
main(), and it should display the results of the test on a serial terminal
window on your PC. It should compile with no errors.
Don't include a lot of useless Wizard code that disables the Timers,
and other peripherals that are already disabled on power-up anyway.
Just delete those lines before you compile and test your program.
Also post your compiler version. |
|
|
|