SPL GPIO TristatePort programming - How to start GPIO TristatePort programming


1. TristatePort
  1. TristatePort is a combined port of InputPort and OutputPort.

  2. It works one of input port or output port.

  3. If "Active" propery is set as "true", it works as output port.

  4. If "Active" propery is set as "false", it works as input port.

  5. You can change "Active" property dynamically on the runtime.
 



2. Add "TristatePort" command
  1. Double click "TristatePort" item on the tree.



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


  2. You can change "Pin" number as one of between 5 ~ 10.

  3. You can change "GlitchFilter" as true.

  4. You can change "ResistorMode" as one of among the "PullUp, PullDown, and Disabled".

  5. You can change "Active" as one of among the "true and false".

  6. In above sample, tristate port was set as "OutputPort" because its Active option was set as "true".



3. Add simple logic to change current state of port
  1. You can change the state of port only for the Output Port.

  2. You can use below methods to read and write state.

       portname.Read()
       portname.Write(bool state)

  3. Add lines to read and change current state of port.



      
    TristatePort    port8
    	/Pin:8
    	/InitialState:false
    	/GlitchFilter:false
    	/ResistorMode:PullDown
    	/Active:true
    	
    s = port8.Read()
    s = !s
    port8.Write(s)
    print "Port8's state was set as " + s
    
      



4. Re-launch SPL emulator
  1. if SPL emulator is running, please terminate emulator.

  2. Press "F5" key to re-launch SPL emulator on the editor.




5. Send SPL script to emulator
  1. Click "Send Script" button to send SPL script to emulator



  2. Executed result will be shown as follows.




6. How to change the function of tristate port from output port to input port
  1. Continued in the next tutorial.