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 support@ccsinfo.com

Software I2C using porta on 16f877a problem

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



Joined: 25 Jul 2006
Posts: 3

View user's profile Send private message

Software I2C using porta on 16f877a problem
PostPosted: Tue Jul 25, 2006 2:56 am     Reply with quote

Hi,

I am trying to create a software I2C port to use two pins on porta of the 16f877a i'm using (PIN_A3=SDA, PIN_A2=SCL). I cannot use the standard C3/C4 pins as these are in use for a SPI connection. For some reason I am getting nothing out of the pins (using a scope to check the output).

To program the device I'm using a ICD2 and I'm using v3.215 of CCS.

In an effort to try to find out why I cant seem to get this to work I have stripped out the rest of my program and left myself with the following code:

Code:

#include "16F877.h"
#device ICD=TRUE
#fuses RC, NOWDT, NOPUT, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay (clock=4000000)

#use i2c ( MASTER, SDA=PIN_A3, SCL=PIN_A2, SLOW=50000)

short     loopForever=1;

void main ()
{
     setup_adc_ports(NO_ANALOGS);
     set_tris_a(0x00);
     
     while (loopForever==1) {
          i2c_start();
          i2c_write(0x0A);
          i2c_write(0x0A);
          i2c_write(0x0A);
          i2c_write(0x0A);
          i2c_stop();
     }
}


If anyone has any ideas, I would be most grateful,

Shaun
Ttelmah
Guest







PostPosted: Tue Jul 25, 2006 4:12 am     Reply with quote

Obvious first comment, have you got the pull-up resistors?.
I'd get rid of the TRIS statement.
The way software I2C is done, is that the port is programmed to pull 'down', and then the tris bit is set to '1' (input), to give a high out (pulled up by the resistors), or to '0' to drive the pin low. I2C, wants to start with the two pins _high_, which requires the TRIS to be set as inputs, not outputs. Though the latter data should appear (the code will be changing the TRIS), you will not get the 'start' bit pattern, since the lines have been driven by your TRIS statement.

Best Wishes
shew82



Joined: 25 Jul 2006
Posts: 3

View user's profile Send private message

PostPosted: Tue Jul 25, 2006 4:30 am     Reply with quote

Ttelmah wrote:
Obvious first comment, have you got the pull-up resistors?


I knew there must have been something obvious that i'd missed!

I'm currently using a standard pic development board (until a more specialist board has been made) which lacks pull-ups on A2 and A3... so tried using A0 and A4 (both pulled up) and voila! working like a charm!

All I need to do now is check that the board thats being made has appropriate pull-ups as well...

Thank you for you quick reply :-)

Shaun
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