|
|
View previous topic :: View next topic |
Author |
Message |
Barney
Joined: 18 Oct 2004 Posts: 41 Location: Newark, CA
|
i2c hang |
Posted: Tue Oct 19, 2004 3:07 pm |
|
|
I am using CCS 3.212 with the Microchip IDE & ICD-2. I am trying to talk to a AD7416 temperature sensor using a 16F87 PIC and I2C. I am getting hung up in call to an initialization routine to setup the AD7416. I turn on a LED before (A0) and another LED (A1) after the call. The first LED comes on, the second does not. If I comment out the call to init_i2c(), then both LEDs come on.
I have tried this both in ICD2 debug mode and non-debug (ICSP) and get the same thing. If I remove the ICD2 and reset the PIC, again the same thing. In debug mode, I watched it loop endlessly in a portion of the code generated for the #use i2c statement.
This seems pretty simple, I don't see what I am doing wrong. Reading the prior posts, apparently there has been issues with the I2C complier code in the past. Any ideas?
Thanks
Barney
#include <16F87.h>
#fuses NOWDT, NOPROTECT, NOLVP, INTRC_IO
#use delay(clock=8000000)
#use standard_io(A)
#use standard_io(B)
#use i2c(master, sda=PIN_B1, scl=PIN_B4)
//B1 = SSP I2C SDA, B4 = SSP I2C SCL
void init_i2c();
void main(){
disable_interrupts(GLOBAL);
output_bit(PIN_A0, 1);
init_i2c(); //initialize i2c addr 0
output_bit(PIN_A1, 1);
}
void init_i2c(){
//set pointer register for temperature register
i2c_start();
i2c_write(0x90); //address & write cmd
i2c_write(0); //set ptr reg to 0 (temperature)
i2c_stop();
} |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Oct 19, 2004 4:35 pm |
|
|
Did ya put pullups on the I2C lines? |
|
|
Guest
|
|
Posted: Wed Oct 20, 2004 1:57 pm |
|
|
Doh! Put on the 1K pull up resistors and it worked like a champ!
Thanks |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Wed Oct 20, 2004 5:46 pm |
|
|
For a 5v system it is uaually recommended to use pull-ups biger than 1.6K. I always use 3.9k and have never had any problems. |
|
|
|
|
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
|