Refferencing MCP23s17 inputs/outputs in GVL

mbruck
2015-09-09
2015-09-10
  • mbruck - 2015-09-09

    I want to create and map custom boolean variable list to point to MCP23S17 input/output pins. Only what I figure out is this.

    I have created global variable list like this:

    VAR_GLOBAL
       in1:BOOL (MCP23S17.byInputsA.0);
       out1:BOOL (MCP23S17.byOutputsA.0);      
    END_VAR
    

    Then in POU's ST code this:

    out1:=in1
    

    Is this syntax ok? What is the "proper" way to create variable map list to mpc's pins ?

    Thank you !

     
  • fixstuff555 - 2015-09-10

    If you want something that works, it may not be exactly what you want but I would just instantiate the device in the globals, like so:

    MCP1: MCP23S17;
    in1: BOOL;
    out1: BOOL;
    

    and then use in the ST code of the POU like this:

    in1:=MCP1.byInputsA.0;
    out1 := in1;
    MCP1.byOutputsA.0 := out1:
    

    or this:

    MCP1.byOutputsA.0 := MCP1.byInputsA.0;
    

    Not sure if you can define like you want to in the globals somehow, but I could be wrong..

     
  • mbruck - 2015-09-10

    .....
    My intention was to declare all inputs and outputs boolean variables in one (global) place, so I can use it on several POU's.
    I know I can use this code MCP1.byOutputsA.0 := MCP1.byInputsA.0; but i'd like to use more meaningful input/output names.
    However I still don't know is this

    VAR_GLOBAL
       in1:BOOL (MCP23S17.byInputsA.0);
       out1:BOOL (MCP23S17.byOutputsA.0);      
    END_VAR
    

    correct or not ?

     

Log in to post a comment.