This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to read chunk of data from Peripheral\SPIS Example

Hi,

       I'm trying to implement a  SPI Communication between Arduino UNO and PCA10056 DK.  PCA10056 DK run as a SPI slave.. Arduino uno run as a SPI Master. 

      The problem is SPI Master keep sending a chunk of data (size - 25 bytes ) by each second..  But I'm unable to receive 25 bytes  from PCA 10056 board.

       Sometimes I receive 10 bytes or 12 bytes... not sure why it happening

       Is it any Mode issue or Clock div?

Parents Reply Children
  • #define TEST_STRING "Nordic"
    static uint8_t       m_tx_buf[25];           /**< TX buffer. */
    static uint8_t       m_rx_buf[25];    /**< RX buffer. */
    static const uint8_t m_length =25;        /**< Transfer length. */
    //static char     m_buf={0};
    
    static volatile bool spis_xfer_done; /**< Flag used to indicate that SPIS instance completed the transfer. */
    
    /**
     * @brief SPIS user event handler.
     *
     * @param event
     */
    void spis_event_handler(nrf_drv_spis_event_t event)
    {
        if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
        {
    	spis_xfer_done = true;
    		//if(event.rx_amount>2)
    		//{
                NRF_LOG_INFO(" Transfer completed. Received: %d   %X",event.rx_amount);//,m_rx_buf[0]);//event.rx_amount,m_rx_buf[0],m_rx_buf[1],m_rx_buf[2]);
    		//}
        }
    }
    
    int main(void)
    {
        // Enable the constant latency sub power mode to minimize the time it takes
        // for the SPIS peripheral to become active after the CSN line is asserted
        // (when the CPU is in sleep mode).
        NRF_POWER->TASKS_CONSTLAT = 1;
    
        bsp_board_init(BSP_INIT_LEDS);
    
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_INFO("SPIS example");
    
        nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;
        spis_config.csn_pin               = APP_SPIS_CS_PIN;
        spis_config.miso_pin              = APP_SPIS_MISO_PIN;
        spis_config.mosi_pin              = APP_SPIS_MOSI_PIN;
        spis_config.sck_pin               = APP_SPIS_SCK_PIN;
        APP_ERROR_CHECK(nrf_drv_spis_init(&spis, &spis_config, spis_event_handler));
    
        while (1)
        {
            memset(m_rx_buf, 0, m_length);
            spis_xfer_done = false;
    
            APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));
            while (!spis_xfer_done)
            {
                __WFE();
            }
    
            NRF_LOG_FLUSH();
    
            bsp_board_led_invert(BSP_BOARD_LED_0);
        }
    }

     The amount of received byte ...I'm printing it on console.

  • spis_config has a parameter:

    spis_config.mode = NRF_SPIS_MODE_0, which is set by NRF_DRV_SPIS_DEFAULT_CONFIG;

    Try all the modes with your SPIM:

    NRF_SPIS_MODE_0
    NRF_SPIS_MODE_1
    NRF_SPIS_MODE_2
    NRF_SPIS_MODE_3

    And see if you receive all the data with any of these. Perhaps the master is using another mode than NRF_SPIS_MODE_0.

    BR,
    Edvin

Related