SPI communication in REXLANG

  • Hello, I'm Tobby, the user of REXYGEN, trying building a project using raspberry pi via SPI to communicate with asic. I've programmed according to the example "0503-02_MCP3008_ADC", but it showed that openspi failed. I'm wondering why.


    Best Regards,
    Tobby Lin

  • Hi Tobby,
    did you enable SPI on your Raspberry Pi? Try running this in the Linux terminal:

    sudo ls /dev/spi*

    If you get "No such file or directory" response, SPI is not enabled. In such a case, you'll need to add the following to your /boot/config.txt:


    Afterwards reboot your RPi and you should be up&running.

    Kind regards,

  • Thanks ! It worked !
    other problems:

    1. How to assign a value to spi_bufTx[0] if I need SPI_MODE0 = 0 and MSBFIRST?
      ( spi_bufTx[0] = ___ ; //SPI data mode (0-3 mode, | 4=CS_HIGH | 8=LSB_FIRST | 16=3WIRE | 32=LOOP | 64=NO_CS | 128=READY) )
    2. Is there any time delay function in C file including in REXLANG?
    3. Can I decide the value of CS0 (GPIO8 of raspberry pi) by setting up CS0 =1 or 0 in C file?

    Best Regards,
    Tobby Lin

  • Hi,

    1. In this case you just use
    spi_bufTx[0] = 0;

    If you wanted e.g. SPI_MODE = 2 and LSBFIRST, you would use

    spi_bufTx[0] = 2 | 8;

    In other words, the first 2 bits define mode, the 3rd bit defines CS behavior, the 4th defines LSB etc.

    1. CS signal is controlled by operating system. You can only change its behavior by the 3rd bit as mentioned above.

    As for the delay function, I have turned it into a separate topic.

    Best regards,

Log in to reply