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

Software I2C master problem

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








Software I2C master problem
PostPosted: Thu May 03, 2007 7:40 am     Reply with quote

The device hangs up when I do not use the I2C hardware pins.

When I use PIN_B6 for SCL it works, and pin A4 is toggling, so do the I2C pins.

When I use PIN_B7 (or any other pin) for SCL there is no activity on pin A4 or the I2C pins.

Any ideas?

I need to use software I2C, I will later on use 2 I2C ports...

Code:
#include <16F690.h>
#device adc=8


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled

#use delay(clock=8000000)

#define SC_SDA PIN_B4
#define SC_SCL PIN_B6

#use i2c(Master, sda=SC_SDA, scl=SC_SCL, slow, STREAM=SC1 )

void main()
{
   int16 x;
   int8 y;
     
   set_tris_a(4);
   output_a(4);
   
   while(TRUE) {
     
      x = 12345;
      y = 12;
     
      i2c_start( SC1 );
      i2c_write (SC1, make8(x,1));
      i2c_write (SC1, make8(x,0));
      i2c_write (SC1, y);
      i2c_stop( SC1 );   
   
      output_low(PIN_A4);
      delay_ms(50);
      output_high(PIN_A4);
      delay_us(10);
   }
}
Guest








PostPosted: Thu May 03, 2007 7:45 am     Reply with quote

This works!

#define SCENECAM_SDA PIN_C6
#define SCENECAM_SCL PIN_B4


This makes the compiler hang!

#define SCENECAM_SDA PIN_B4
#define SCENECAM_SCL PIN_C6
Guest








PostPosted: Thu May 03, 2007 7:52 am     Reply with quote

C0 and C1 does not work together either! :(
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu May 03, 2007 9:00 am     Reply with quote

Quote:
#use i2c(Master, sda=SC_SDA, scl=SC_SCL, slow, STREAM=SC1 )


I2C statements do not use a 'Stream'. This is for defining multiple RS232 ports. Try taking that out of your #USE statement and see what happens.

Ronald
strombom



Joined: 04 May 2007
Posts: 4

View user's profile Send private message

PostPosted: Fri May 04, 2007 12:57 am     Reply with quote

According to the manual it does:

STREAM=id
Associates a stream identifier with this I2C port. The identifier may then be used in functions like i2c_read or i2c_write.


I also got this answer from support before I bought the compiler:

Code:

Do something like:
 
#use i2c(Master,Slow,sda=PIN_B4,scl=PIN_C6, STREAM=ONE)
#use i2c(Master,Slow,sda=PIN_C0,scl=PIN_A2, STREAM=TWO)

i2c_start( ONE );
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri May 04, 2007 10:30 am     Reply with quote

Okay, I don't use Version 4 yet because of the bugs and Stream was not an option in V3.xxx.

Ronald
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