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

SPI Communication

2014-06-25
2014-06-27
  • yannickasselin1

    yannickasselin1 - 2014-06-25

    Hi all,
    I want to test some SPI communication and don't know where to start.
    I just want to send some bytes through SPI. Don't need to receive for now.
    I don't want to build a library for now. Can I just use the base library and declare a variable of type SPI?
    Can I just use the "transfer" method or do I need to use the "init" method first? Don't know where to start.
    I looked at the exemple for the piFace and the temperature sensor and cannot figure out how this works.
    Is there any documentation on how to use the SPI library? Can't find any.

    Please help...

    Thanks!

     
  • eschwellinger

    eschwellinger - 2014-06-27

    Hi,
    please open the SPI_PIFace.library,
    here you see how it could be realized. (This works for the project too, you need only to add Raspberry Pi Peripherals linrary to your project)
    Basically it is the method transfer which you need to use for reading and writing:

    snippet:

    abyTxBuffer[0] := 16#40 + SHL(byHardwareAddress, 1); //SPI_WRITE_CMD;
    abyTxBuffer[1] := byPort;
    abyTxBuffer[2] := byValue;
    write8 := transfer(pabyTxBuffer:=ADR(abyTxBuffer) , pabyRxBuffer:=ADR(abyRxBuffer) , udiLen:=3 , uiDelayus:=5 );
    
    abyTxBuffer[0] := 16#40 + SHL(byHardwareAddress, 1) + 1; //SPI_READ_CMD;
    abyTxBuffer[1] := byPort;
    abyTxBuffer[2] := 16#FF;
    transfer(pabyTxBuffer:=ADR(abyTxBuffer) , pabyRxBuffer:=ADR(abyRxBuffer) , udiLen:=3 , uiDelayus:=5 );
    read8 := abyRxBuffer[2];
    

    BR
    Edwin

    IMG: SPI_Write.jpg

    IMG: SPI_Read.jpg

    IMG: SPI_LIB.jpg

     

    Related

    Talk.ru: 1
    Talk.ru: 2


    Last edit: eschwellinger 2021-08-25

Log in to post a comment.