GPIO Tristate port programming


1. Add GPIO Tristate port
  1. Use "TristatePort" command to add new GPIO tristate port.

  2. Select "Application" tab.

  3. Add a new GPIO Tristate port as follows.

      
    clear
    
    TristatePort    port8
    	/Pin:8
    	/InitialState:false
    	/GlitchFilter:false
    	/ResistorMode:PullDown
    	/Active:true
    
      
 

  1. "/Active:true" means this port will be set as a output port.

  2. If your change this Active property as false, this port will be set as an input port.

  3. Click "Send to MF Application" button or Press "F5" key.

  4. Executed result:




2. Change the state of GPIO port by using "Write(bool)" method
  1. Use "Write(bool)" method to change current state.

  2. 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
    
      


  3. Click "Send to MF Application" button or Press "F5" key.

  4. Executed result:




3. Change the port type as an input port by set "Active" property as false
  1. Tristate port can act as an output port or as an input port. This depends on its "Active" property.

  2. In order to change the type of current port as input port, set its "Active" property as false.

  3. Type below script on the editor in order to change the type of port.

      
    port8.Active = false
    
      


  4. Click "Execute Script on the Emulator" button or Press "F5" key.




4. Change the port state through emulator
  1. You can't change the state of tristate port in the application itself if its type is input port.

  2. In order to change (or write to port) the state, you have to use emulator script.

  3. Select Emulator tab.

  4. Type below script on the emulator's editor in order to change the state of tristate port.

      
    port8.Write(false)
    
      


  5. Click "Execute Script on the Emulator" button or Press "F5" key.



  6. Executed result:



  7. You will see the log message that Port8's state was set as false.



5. Read changed state from aplication
  1. Select Application tab

  2. Execute below script again on the Application tab in order to read changed value.

      
    state = port8.Read()
    
    print "State of Pin8 is " + state
    
      


  3. Click "Send to MF Application" button or Press "F5" key.

  4. Executed result:



  5. You can see the state of tristate port was changed as false.