Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Stefan2 I2C library examples

pawel3410
2019-06-24
2019-06-29
  • pawel3410 - 2019-06-24

    Hello.

    Does anyone have any examples how to use devices from this library?
    Especially how to use 24C512?

     
  • Stefan2 - 2019-06-29

    Hi Pawel,

    sure I know this…

    The eeprom works assyncron call it like this:

       IF SysSem.SysSemEnter(hSem:=PARAM_DATA.DATA_EEPROM.SEMAPHORE) = SysSem.Errors.ERR_OK THEN
          IF PARAM_DATA.DATA_EEPROM.FB_NO_IN = 0 THEN
             PARAM_DATA.DATA_EEPROM.FB_NO_IN := PARAMETER_NO;
             PARAM_DATA.DATA_EEPROM.WRITE_VALUE := TRUE;
             PARAM_DATA.DATA_EEPROM.VALUE_IN.LWORD_T := PARAM.LWORD_T;
             PARAM_DATA.DATA_EEPROM.ADDRESS_VALUE := GET_PAGE_ADRESS_EEPROM(DATA:= PARAM_DATA);
          END_IF   
       END_IF
       SysSem.SysSemLeave(hSem:=PARAM_DATA.DATA_EEPROM.SEMAPHORE);
    

    try to use the device as no multiplex in device config.

    PARAM_DATA.DATA_EEPROM.FB_NO_IN = 0 THEN
    
    ``` shows that the EEPROM is read to recive new command.
    
    FB_NO_IN can be any UNIQUE number on your PLC this number shows the write or reciving FB that data for this FB is avalible. I create thos Nums by call 
    >**Zitat:**
    DB_IN_OUT^.FB_NO_AUTO := DB_IN_OUT^.FB_NO_AUTO + 1;
    
    
    in each FB
    and reset them in on FB like:
    

    DB_IN_OUT.FB_NO_AUTO := 0;//reset FB number

    
    

    IF DATA_EEPROM.FB_NO_OUT = PARAMETER_NO THEN
       //got my request back

    shows that data from eeprom is avalible.
    
    then you can receive the data like this:
    

    IF DATA_EEPROM.FB_NO_OUT = PARAMETER_NO THEN
       //got my request back   
       //get value
       VALUE_FROM_EEPROM.LWORD_T := DATA_EEPROM.VALUE_OUT.LWORD_T;

       DATA_EEPROM.FB_NO_OUT := 0;//delete response
       LOAD_VALUE_FROM_EEPROM := FALSE;//delete request
    END_IF

    ```

    I think I have to make a god example too.

    BR Stefan

     

Log in to post a comment.