vincenthimpe Regular Member
 Joined: 14/10/2018 Location: United StatesPosts: 86 |
| Posted: 12:47am 09 May 2025 |
|
|
|
Added some more commands: - Enable/disable the actual input sampler on a pin - Read the pin state directly
When a pin is set to Dout in MMbasic you are not reading the actual pin state when using the PIN command.
SETPIN GP1,DOUT pin (gp1) = 1 print PIN (GP1)
will print '1'. but that '1' is NOT coming from the actual pin. It is read from the output register. MMBasic turns off the return sampler for the pin
GPIO.INen (gpio) can turn on the actual input sampler on a pin GPIO.Sample (gpio) then reads the actual level on the pin, and not from the output buffer.
Any pin where GPIO.INen is active also shows up in the GPIOPread return value. so you can parallel read.
GPIO.INdis switches the sampler off. That way the return value of a true output does not show up in the GPIO.Pread
This is useful if you need to do wired-or operations or things like bitbanging I2C
Setpin GP3,Dout ' standard mmbasic GPIO.Openmode 3,1 ' Open GPio3 in open collector with pull-up enabled GPIO.Inen 3 ' Enable the input sampler
print GPIO.Sample (3) GPIO.Drive 3 ' will set the pin HARD LOW (since it was set as open collector) GPIO.Float 3 ' will disable the output driver so the pin goes high through the pullup
These commands override any other activity from peripherals. I need to try shunting a serial port TXRX pair and flicking the GPIO of TX in float mode. It should be possible to do half duplex over 1 wire. Float TX and you can recaive. if you need to transmit : reactivate the driver. You can do ping-pong between 2 processors. After receiving a frame you need to reply. Things like modbus should be possible Edited 2025-05-09 10:50 by vincenthimpe |