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

'releasing' an open collector output

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







'releasing' an open collector output
PostPosted: Tue Jul 22, 2008 8:40 am     Reply with quote

Hi, I'm trying to convert a snippet of code for an atmega168 to a 16f88. Here it is:

Code:

   //Release data and clock lines so that the computer can take over clock if needed
   DDRC &= ~( (1<<CLK_OUT) | (1<<DATA_OUT) ); //Release control of clock/data (1 = output, 0 = input)
   PORTC |= (1<<CLK_OUT) | (1<<DATA_OUT); //Enable pull up on clock/data
   
   while( (PINC & (1<<CLK_OUT)) == 0) //Wait for computer to release clock. Computer will hold clock down to inhibit bus
   {
      //If we see the data line go low, then the computer is trying to send a command
      if( (PINC & (1<<DATA_OUT)) == 0) break;
   }


Which I have changed to the following in CCS (v4.074):
Code:

   input(DATA_OUT);
   input(CLK_OUT);
   port_b_pullups(TRUE);

   while( input(CLK_OUT) == 0) //Wait for computer to release clock.
   {
      output_high(PIN_LED);
      //If we see the data line go low, then the computer is trying to send a command
      if( input(DATA_OUT) == 0) break;
   }
   output_low(PIN_LED);


This is for a ps2 keyboard emulator... the data and clock lines should be held high by pullups when not in use. Not shown here (as it's output is fine) is the code to output the command byte. However, my logic analyzer shows the clock line is held low indefinitely, after the command byte has been sent. Any ideas why that is?

Thanks

Rich
rich
Guest







PostPosted: Tue Jul 22, 2008 9:01 am     Reply with quote

Hmm.. I'm not sure, but I'm beginning to wonder if the computer is pulling it low because it doesnt like something I've sent it.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 22, 2008 12:50 pm     Reply with quote

Post a very small test program that incorporates your code above.
Specifically, I want to see if you are using #fast_io mode.
rich
Guest







PostPosted: Wed Jul 23, 2008 6:07 am     Reply with quote

Yes, I'm being lazy and using the auto io mode, so that input() should set the pin to an input.

More than anything, I'm wondering how port_b_pullups should be used... before or after the calls to input? All I want to do is release control of the line and let the pull up resistor make it float high Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 23, 2008 3:25 pm     Reply with quote

Quote:

More than anything, I'm wondering how port_b_pullups should be used,
before or after the calls to input ?

Just enable them at the beginning of the program. Then they will be
automatically turned on/off by the PIC depending on whether the Port B
pin is configured as an input or output.
Section 3.2 of the 16F877 data sheet says this:
Quote:

Each of the PORTB pins has a weak internal pull-up.
The weak pull-up is automatically turned off when the
port pin is configured as an output.


Quote:

All I want to do is release control of the line and let the pull up resistor
make it float high.

Use the output_float() function to make an individual pin into an input pin.
rich
Guest







PostPosted: Thu Jul 24, 2008 8:40 am     Reply with quote

That's very useful info - thanks very much for your help Smile
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