6 Replies Latest reply on Dec 3, 2016 9:34 AM by Lockdog

    Has anyone tried to use SPI with peripheral devices?

    Lockdog

      Hello,

      I'm trying to connect radio chip to the D2000 through SPI. Has anoyone tried to do something more than Intel's example?

        • 1. Re: Has anyone tried to use SPI with peripheral devices?
          SergeyK

          Yes, I was able to connect a Nordic nRF24L01 radio to the Quark D2000 Board. The driver code including a couple of simple examples is here: GitHub - skiselev/rf24-qmsi: RF24 port for Intel QMSI

          I likely need document it :-)

          The API is similar to the Arduino nRF24L01 library API. Copy files from the "board" directory to the "bsp/board" in your QMSI project, and use main.c and Makefile files from the examples directory as a starting point.

          • 2. Re: Has anyone tried to use SPI with peripheral devices?
            Lockdog

            Hi, Sergey!

            Thanks for your reply.

            I see the comment in your code:

            /* Use GPIO for slave select due to bug in DesignWare SPI */
            /* qm_pmux_select(QM_PIN_ID_0, QM_PMUX_FN_2);*/  /* SS0 */
            

            And I thought, that my device doesn't work because of the same bug

            I have added gpio controlled ChipSelect routines too, but wthout success. I'm trying to run SX1272 radio. And I should read register from it like below:

            uint8_t readRegister(uint8_t addr)
            {
              qm_spi_transfer_t polled_xfer_desc;
              qm_spi_status_t status;
            
              uint8_t rx_buf[2];
              uint8_t spi_buf[2];
            
              spi_buf[0] = addr & 0x7F;
              spi_buf[1] = 0xFF;
            
              polled_xfer_desc.tx = spi_buf;
              polled_xfer_desc.rx = rx_buf;
              polled_xfer_desc.tx_len = 2;
              polled_xfer_desc.rx_len = 2;
              sx1272_csn_enable();
              qm_spi_transfer(QM_SPI_MST_0, &polled_xfer_desc, &status);
              sx1272_csn_disable();
            
               return rx_buf[1];
            }
            

            But 0x00 returns any time

            • 3. Re: Has anyone tried to use SPI with peripheral devices?
              SergeyK

              It is difficult to tell why it is not working. Your read register code looks good to me. Did you configure SPI, GPIOs, and pinmux'es? See rf24_init() function in board/drivers/rf24/rf24.c. Otherwise it would be interesting to see the picture from oscilloscope/logic analyzer.

              • 4. Re: Has anyone tried to use SPI with peripheral devices?
                Lockdog

                Yes, SPI configured and works with loopback mode.

                There's Semtech's read register function below:

                void SX1272ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
                {
                    uint8_t i;
                    //NSS = 0;
                    GpioWrite( &SX1272.Spi.Nss, 0 );
                    SpiInOut( &SX1272.Spi, addr & 0x7F );
                    for( i = 0; i < size; i++ )
                    {
                        buffer[i] = SpiInOut( &SX1272.Spi, 0 );
                    }
                    //NSS = 1;
                    GpioWrite( &SX1272.Spi.Nss, 1 );
                }
                
                • 5. Re: Has anyone tried to use SPI with peripheral devices?
                  SergeyK

                  Yes, that function makes sense. I am still wondering if there is an issue on the electrical or pin/SPI configuration side. It would be interesting to see that NSS indeed goes low before each SPI transfer. And then, if possible to observe other SPI signals. Even if you don't have a scope, a multimeter with frequency measurement function might do (if you run the SPI transfer in loop).

                  • 6. Re: Has anyone tried to use SPI with peripheral devices?
                    Lockdog

                    I checked the MISO, MOSI lines by oscilloscope, and no any data transfer. After that I found the bug. Forgot to add this lines:

                    qm_pmux_select(QM_PIN_ID_17, QM_PMUX_FN_2); /* MOSI */
                    qm_pmux_select(QM_PIN_ID_18, QM_PMUX_FN_2); /* MISO */
                    

                    I thought, that RXD and TXD means UART and didn't add them in my code.

                    Thanks!