SPI Communication

2014-06-25
2023-12-23
  • 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
  • ulad - 2023-12-23

    Hello. I created a project that uses SPI. This project is working well. I can see with an oscilloscope that the SPI pins are actually changing.
    But when I resave this project in the IDE and open it later in the system, I see a constant error.
    What do I need to fix? What am I doing wrong?
    Thank you.

     

Log in to post a comment.