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

Setting port for I2C
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rovtech



Joined: 24 Sep 2006
Posts: 262

View user's profile Send private message AIM Address

PostPosted: Mon Jul 13, 2020 2:33 pm     Reply with quote

I'm trying to run a stepper motor synchronized to a sector scan on an LCD (Sonar display).
I have to send a pattern of 4 bits in sequence, either forward or backward, in step with the scan. The pattern is in an array
Code:
char step[4] = {0x03,0x06,0x24,0x21};

the following does not interfere
Code:
     output_high(PIN_C5);

but requires many statements.
Or I could use another port but it does not answer the basic question of how to handle mixed I/O
rovtech



Joined: 24 Sep 2006
Posts: 262

View user's profile Send private message AIM Address

PostPosted: Mon Jul 13, 2020 2:48 pm     Reply with quote

#use fast_io(c) stops freezing the I2C but nothing is Output even the simple
Code:
  output_c (0x03);

I have LEDs to see the states.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 13, 2020 3:09 pm     Reply with quote

#fast_io tells the compiler to not set the TRIS. You must manually do it
with a line of code. If you don't see your LEDs light up, then the TRIS is not
set to be output pins.
rovtech



Joined: 24 Sep 2006
Posts: 262

View user's profile Send private message AIM Address

PostPosted: Mon Jul 13, 2020 4:26 pm     Reply with quote

Sorry, I had set tris to 0xff while testing.
Now the program seems to be working but not if I comment out the #use fast_io(c).
What is happening without fast_io and why does it freeze the I2C? The tris is set to 0x18 so the C4, C3 are inputs.
Why does it work with fast_io? I read the manual but don't fully understand what is happening.
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Mon Jul 13, 2020 5:33 pm     Reply with quote

Without fast_io, the compiler sees that you're trying to set port C to some specific 8 bit value, so it automatically makes all of the pins of port C an output for you. Including your i2c lines (it doesn't care that you originally set them to be inputs). Which, by the way, must be left as inputs. But it doesn't really know/care because this convenient automatic feature trumps all.

Then some time later the i2c code must execute but the compiler isn't intelligent enough to set those two pins back to an input first. Result: code hangs in the first i2c routine.

I'll admit, for those new to PICs and the compiler, having these things taken care of automatically is kind of cool. For anything else, take control yourself: no surprises that way.
rovtech



Joined: 24 Sep 2006
Posts: 262

View user's profile Send private message AIM Address

PostPosted: Mon Jul 13, 2020 6:34 pm     Reply with quote

That really surprises me because without fast_io I had set Tris to 0x18 (mixed I/O).
Does that mean the compiler set them all to output at the first output_c()
??
I'm sure I have written programs without fast_io that used input and output pins and I never had any trouble. Perhaps I read them individually.
Thanks, I will watch that carefully.
My stepper is running nicely and I'm trying to find out how many degrees per step. It appears to be 1000 steps for 180 degrees and I have suspected it had gears from the shape, so 0.18 deg/step.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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