View previous topic :: View next topic |
Author |
Message |
rich Guest
|
'releasing' an open collector output |
Posted: Tue Jul 22, 2008 8:40 am |
|
|
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
|
|
Posted: Tue Jul 22, 2008 9:01 am |
|
|
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
|
|
Posted: Tue Jul 22, 2008 12:50 pm |
|
|
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
|
|
Posted: Wed Jul 23, 2008 6:07 am |
|
|
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 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 23, 2008 3:25 pm |
|
|
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
|
|
Posted: Thu Jul 24, 2008 8:40 am |
|
|
That's very useful info - thanks very much for your help |
|
|
|