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

SPIS of nrf52 could not read the data accuracy

I am working with SPIS example ( sdk version 15.3). SPI master send data regulaly. For example, it sent 5ms cs low, but there are only two bytes transferred, the first byte at begin of 5ms, other one at the end. SPIS of nrf52  not read the second one, what can I do with it?

Parents
  • hzhuxin said:
    What i ask is, if master send these data to me, i should received two bytes, am i right?
    But in fact, only one bytes could be received.

     Ok. So the issue is not that you are missing a lot of information in between the two bytes, but that you only read the second byte. Now I understand. And you only get the second byte, was that so? So you are missing the first?

    Can I see how you set up, and how you read your SPI(S) on the nRF? Can you try with the SDK\examples\peripheral\spis example?

  • Thanks.

    But i should confirm i lost the second byte, not the first!

    And i check the spis_event_handler parameter event, event.rx_amount is always 1, so i can make sure the second byte lost.

    /**
     * Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    #include "nrf_delay.h"
    #include "sdk_config.h"
    #include "nrf_drv_spis.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    #include "app_error.h"
    #include <string.h>
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #define SPIS_INSTANCE 1 /**< SPIS instance index. */
    static const nrf_drv_spis_t spis = NRF_DRV_SPIS_INSTANCE(SPIS_INSTANCE);/**< SPIS instance. */
    
    #define TEST_STRING "Nordic 1234567890123"
    static uint8_t       m_tx_buf[] = TEST_STRING;           /**< TX buffer. */
    static uint8_t       m_rx_buf[sizeof(TEST_STRING) + 1];    /**< RX buffer. */
    static const uint8_t m_length = sizeof(m_tx_buf);        /**< Transfer length. */
    
    static volatile bool spis_xfer_done; /**< Flag used to indicate that SPIS instance completed the transfer. */
    
    /**
     * @brief SPIS user event handler.
     *
     * @param event
     */
    
    #define DATA_BUFFER_SIZE 2000
    void spis_event_handler(nrf_drv_spis_event_t event)
    {
        static uint8_t MyString[DATA_BUFFER_SIZE];
        static uint8_t MyStringIndex = 0;
        int i, j;
        uint8_t *StartPointer, *NextPointer;
        if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
        {
            spis_xfer_done = true;
            if (MyStringIndex == DATA_BUFFER_SIZE)
             {
                NRF_LOG_INFO(" Transfer completed. Received: %d\n", MyStringIndex);
    
                //Find the first Data
    /*            for (i = 0; i < DATA_BUFFER_SIZE; i ++)
                  if (MyString[i] == 0x80 || MyString[i] == 0x90 || MyString[i] == 0xa0)
                  break;
    
                if (i < DATA_BUFFER_SIZE)
                {
                  StartPointer = &MyString[i]; 
    
                while ((StartPointer != NULL) && (StartPointer < (&MyString[DATA_BUFFER_SIZE - 1])) && (StartPointer + 16 < (&MyString[DATA_BUFFER_SIZE - 1])) )
                {
                  NextPointer = StartPointer + 1;
                  //Find the ending of the data
                  for (j = 1; j < 16; j ++, NextPointer ++)
                  {
                    if (*NextPointer == 0x80 || *NextPointer == 0x90 || *NextPointer == 0xa0)
                    break;
                  }
    
                  //Show the data to RTT or UART
                  NRF_LOG_HEXDUMP_INFO(StartPointer, j);
                  StartPointer += j;
                }
    
                memset(MyString, 0, 100);
                MyStringIndex = 0;
              }
             }*/
             MyString[MyStringIndex] = m_rx_buf[0];
             MyStringIndex ++;
      }
    }
    
    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.mode = NRF_SPIS_MODE_0;
        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)
        {
            spis_xfer_done = false;
    
            APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, 0, m_rx_buf, 1));
    
            while (!spis_xfer_done)
            {
                __WFE();
            }
    
            NRF_LOG_FLUSH();
    
    //        bsp_board_led_invert(BSP_BOARD_LED_0);
        }
    }
    

Reply
  • Thanks.

    But i should confirm i lost the second byte, not the first!

    And i check the spis_event_handler parameter event, event.rx_amount is always 1, so i can make sure the second byte lost.

    /**
     * Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    #include "nrf_delay.h"
    #include "sdk_config.h"
    #include "nrf_drv_spis.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    #include "app_error.h"
    #include <string.h>
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #define SPIS_INSTANCE 1 /**< SPIS instance index. */
    static const nrf_drv_spis_t spis = NRF_DRV_SPIS_INSTANCE(SPIS_INSTANCE);/**< SPIS instance. */
    
    #define TEST_STRING "Nordic 1234567890123"
    static uint8_t       m_tx_buf[] = TEST_STRING;           /**< TX buffer. */
    static uint8_t       m_rx_buf[sizeof(TEST_STRING) + 1];    /**< RX buffer. */
    static const uint8_t m_length = sizeof(m_tx_buf);        /**< Transfer length. */
    
    static volatile bool spis_xfer_done; /**< Flag used to indicate that SPIS instance completed the transfer. */
    
    /**
     * @brief SPIS user event handler.
     *
     * @param event
     */
    
    #define DATA_BUFFER_SIZE 2000
    void spis_event_handler(nrf_drv_spis_event_t event)
    {
        static uint8_t MyString[DATA_BUFFER_SIZE];
        static uint8_t MyStringIndex = 0;
        int i, j;
        uint8_t *StartPointer, *NextPointer;
        if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
        {
            spis_xfer_done = true;
            if (MyStringIndex == DATA_BUFFER_SIZE)
             {
                NRF_LOG_INFO(" Transfer completed. Received: %d\n", MyStringIndex);
    
                //Find the first Data
    /*            for (i = 0; i < DATA_BUFFER_SIZE; i ++)
                  if (MyString[i] == 0x80 || MyString[i] == 0x90 || MyString[i] == 0xa0)
                  break;
    
                if (i < DATA_BUFFER_SIZE)
                {
                  StartPointer = &MyString[i]; 
    
                while ((StartPointer != NULL) && (StartPointer < (&MyString[DATA_BUFFER_SIZE - 1])) && (StartPointer + 16 < (&MyString[DATA_BUFFER_SIZE - 1])) )
                {
                  NextPointer = StartPointer + 1;
                  //Find the ending of the data
                  for (j = 1; j < 16; j ++, NextPointer ++)
                  {
                    if (*NextPointer == 0x80 || *NextPointer == 0x90 || *NextPointer == 0xa0)
                    break;
                  }
    
                  //Show the data to RTT or UART
                  NRF_LOG_HEXDUMP_INFO(StartPointer, j);
                  StartPointer += j;
                }
    
                memset(MyString, 0, 100);
                MyStringIndex = 0;
              }
             }*/
             MyString[MyStringIndex] = m_rx_buf[0];
             MyStringIndex ++;
      }
    }
    
    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.mode = NRF_SPIS_MODE_0;
        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)
        {
            spis_xfer_done = false;
    
            APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, 0, m_rx_buf, 1));
    
            while (!spis_xfer_done)
            {
                __WFE();
            }
    
            NRF_LOG_FLUSH();
    
    //        bsp_board_led_invert(BSP_BOARD_LED_0);
        }
    }
    

Children
  • when i set the breakpoint at line 80, i found all the data i recevied to buffer "MyString", lost the second bytes.

    i received data from SPIM should be 17 bytes every time, the first and the second byte using the same cs signal, but all the other 15 bytes using 15 cs signal individual, and the cs interval always in 500ns. so i got the first byte, lost the second byte, and then got all the other byte correctly.

    so i think there are some problem for long time cs valid and not clk and data  appear?

Related