I guess it is rpi's hidden built in gpio pull resistor that confuses you.
To avoid the tri state input pin floating, you can pull the pull resistor to either Vdd or ground.
Suppose you pull the built in resistor to ground (0v), then if there is no input, the input pin would read 0V. Similarly, if you pull the resistor to Vcc (3V3), then if there is no input, the input pin would read 3V3.
Now if you pull the built in 1k8 resistor to ground, and your 1k to 3V3, then because there is a voltage divider which divides the 3V3 at the gpio pin to:
3V3 * 1k8 / (1k8 + 1k) == 2V
Now gpio pins reads 2v, instead of your expected 3V3.
You can pull the built in resistor to 3V3. Then if you connect your 1k to 3v, gpio pin would read 3v3. But when your 1k is connected to 0v, gpio pin would NOT read 0v! Why?
Anyway, the problem does not go away, but shifted to the other end.
One usual trick is NOT to use your 1K resistor as the input, but use a 'open drain' or 'open collector' device as the input to the GPIO pin. You also need to pull the built in resistor to 3V3. Then all should go well.
I know it is complicated, but that is 'advanced' electronics！
My apologies for my wrong information about the wrong pull up/down resistor value of 1k8, and the wrong description about the 'floating' input.
I remember I often read that a weak resistor should be around 100k. So my 1k8 should be WRONG.
My description of "floating input" is misleading. I should have said that if the input to the gpio pin is tristate, say from the tristate output of a disabled cmos cricuit, then the gpio pin would see arbitrary or indeterministic values. And a pull up resistor can avoid the floating problem by pulling up or down, so that the gpio pin would either see high or low, not indeteriministic values.
Actually I wrote the above in a comment, but found I would not save it because I spent more than 5 minutes editing. I am slow in writing English, so I think I should have edited my comments using an editor and then copy and paste it here as a comment.
I googled again for the rpi pull up value. I found the forum saying rpi i2c internal pull up is 1k8. But another forum says official i2c external pull up is 1k8. However, a couple of other forums say the rpi pull up is 50k. It is indeed confusing.
* i2c pull up resistors *
... Since the RPi board already has 1.8K resistors on the I2C lines, ...
* Rpi i2c pullup configurations *
... The official I2C bus has 1K8 external pullups to 3V3 ...
I googled again and found someone saying that rpi's i2c pins have 1k8 pull up resistors.
Home→Raspberry Pi→WiringPi→Special Pin Functions
Pins 8 and 9 . . . These are the I2C pins.
. . . note that they have on-board 1.8KΩ resistors pulling the signals to the 3v3 supply.
About tristate inputs, I googled and found the following comment:
ka7ehk Posted : Mon. Apr 2, 2012 - 02:07 AM
“AVR shared digital/analog inputs are, indeed, "tri-state" of a sort. However, as mentioned, this term most often applies to outputs. The AVR documentation does not use this term with respect to inputs, only outputs.”
I now think that my saying of "tristate input" is WRONG. An input may be in the "floating state", but this state is completely different from the output's high impedance state. A shared digital and analogue input can have the analogue buffer disconnected (connection becomes high impedance) but that is not the same as the output's high impedance.
Max and min i2c pull up values.
I googled again and find the following two notes on i2c pin pull up values.
TI pull up calculation
I2C Pull-up resistor calculation
My quick conclusion is that the pull up resistor should be from 200R min up to 1k8 max.
Now I reading online tutorials on tristate circuits and pull up resistors, to clear my mind and remove my misunderstanding of some confusing technical terms. I found the following two tutorials very good.