GPIO Tristate port programming
1. Add GPIO Tristate port
- Use "TristatePort" command to add new GPIO tristate port.
- Select "Application" tab.
- Add a new GPIO Tristate port as follows.
| |
clear
TristatePort port8
/Pin:8
/InitialState:false
/GlitchFilter:false
/ResistorMode:PullDown
/Active:true
| |
|
|
|
|
- "/Active:true" means this port will be set as a output port.
- If your change this Active property as false, this port will be set as an input port.
- Click "Send to MF Application" button or Press "F5" key.
- Executed result:
2. Change the state of GPIO port by using "Write(bool)" method
- Use "Write(bool)" method to change current state.
- Type below script on the editor to change the Pin 8's state.
| |
port8.Write(true)
state = port8.Read()
print "State of Pin8 is " + state
| |
|
- Click "Send to MF Application" button or Press "F5" key.
- Executed result:
3. Change the port type as an input port by set "Active" property as false
- Tristate port can act as an output port or as an input port. This depends on its "Active" property.
- In order to change the type of current port as input port, set its "Active" property as false.
- Type below script on the editor in order to change the type of port.
- Click "Execute Script on the Emulator" button or Press "F5" key.
4. Change the port state through emulator
- You can't change the state of tristate port in the application itself if its type is input port.
- In order to change (or write to port) the state, you have to use emulator script.
- Select Emulator tab.
- Type below script on the emulator's editor in order to change the state of tristate port.
- Click "Execute Script on the Emulator" button or Press "F5" key.
- Executed result:
- You will see the log message that Port8's state was set as false.
5. Read changed state from aplication
- Select Application tab
- Execute below script again on the Application tab in order to read changed value.
| |
state = port8.Read()
print "State of Pin8 is " + state
| |
|
- Click "Send to MF Application" button or Press "F5" key.
- Executed result:
- You can see the state of tristate port was changed as false.
|