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 CCS Technical Support

i2c hang

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



Joined: 18 Oct 2004
Posts: 41
Location: Newark, CA

View user's profile Send private message

i2c hang
PostPosted: Tue Oct 19, 2004 3:07 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Oct 19, 2004 4:35 pm     Reply with quote

Did ya put pullups on the I2C lines?
Guest








PostPosted: Wed Oct 20, 2004 1:57 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 20, 2004 5:46 pm     Reply with quote

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.
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