<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Why cannot log all the printing data when receiving from the SPI?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82711/why-cannot-log-all-the-printing-data-when-receiving-from-the-spi</link><description>Hi Team, 
 When the slave side of the SPI received data from the master side, I want to log the received data to judge If it is right. But, I want to print it by log. it can only view 20 or so characters, Also including some garbled characters. Could</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Dec 2021 07:37:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82711/why-cannot-log-all-the-printing-data-when-receiving-from-the-spi" /><item><title>RE: Why cannot log all the printing data when receiving from the SPI?</title><link>https://devzone.nordicsemi.com/thread/344489?ContentTypeID=1</link><pubDate>Tue, 21 Dec 2021 07:37:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fb31f1d-9cc2-47a6-900f-27e203b1b81b</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Hmm, okay. Can you show me how your log&amp;nbsp;output so I can get a better understanding of what&amp;#39;s going on? Please also explain what you expect?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please also let me know what GPIOs&amp;nbsp;you are&amp;nbsp;using for SPI communication.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
&lt;p&gt;PS:&amp;nbsp;We will be short on staff during the Holiday period, and delayed replies must be expected. We will be back to full staff on January 3rd. Happy holidays and happy new year!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why cannot log all the printing data when receiving from the SPI?</title><link>https://devzone.nordicsemi.com/thread/344283?ContentTypeID=1</link><pubDate>Mon, 20 Dec 2021 09:48:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8db22717-5bf0-4873-ba3f-14c0d87a98c5</guid><dc:creator>lgs</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;I move the logging lines outside of the event handler. It still has the problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why cannot log all the printing data when receiving from the SPI?</title><link>https://devzone.nordicsemi.com/thread/343535?ContentTypeID=1</link><pubDate>Wed, 15 Dec 2021 06:22:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b699ae3e-a19c-4240-85e3-da1febbdef0b</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The &amp;quot;Transfer completed...&amp;quot; messages are printed using UART or RTT, and using the __log printing inside the spis_event_handler() will likely cause this jumbled data you&amp;#39;re seeing. Please move these logging lines outside of the event handler&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why cannot log all the printing data when receiving from the SPI?</title><link>https://devzone.nordicsemi.com/thread/343345?ContentTypeID=1</link><pubDate>Tue, 14 Dec 2021 09:39:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45c09edf-965a-465a-8683-6dd279b4dc89</guid><dc:creator>lgs</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;spis.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;advertiser.h&amp;quot;

#define                SPIS_INSTANCE                1 /**&amp;lt; SPIS instance index. */

bool                   SWITCH2SPI                 = true;
static  const          nrf_drv_spis_t spis        = NRF_DRV_SPIS_INSTANCE(SPIS_INSTANCE);/**&amp;lt; SPIS instance. */                           /** &amp;lt; RX buffer. */
uint8_t                m_rx_buf_spi[BROADCASRLEN] = {0};
volatile uint8_t *     m_tx_buf_spi;
volatile uint8_t       m_tx_length;
static volatile bool   spis_xfer_done;                     /**&amp;lt; Flag used to indicate that SPIS instance completed the transfer. */
volatile bool          g_null_status            = true;


static uint8_t         front_check[3]             = {0xAA, 0xBB, 0xCC};
static uint8_t         rear_check[3]              = {0xDD, 0xEE, 0xFF};

/**
 * @brief  SPIS check completeness of data
 * 1, 3, 4, 7, 34, 37 etc. frameLen + checkNums
 */
bool check_completeness(uint8_t * receicedData)
{
    for (uint8_t i = 1; i &amp;lt; 4; i++)
    {
        if (receicedData[i] != front_check[i - 1])
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;check failed!, front[%d]: rec%d\n&amp;quot;, i, receicedData[i]);
            return false;
        }
    }

    uint8_t dataStatus = receicedData[7];
    if ((dataStatus == 0x04) || (dataStatus == 0x08))
    {
       for (uint8_t j = 0; j &amp;lt; 3; j++)
       {
            if (receicedData[j + 37] != rear_check[j])
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;check failed!, front[%d]: rec:%c\n&amp;quot;, j, receicedData[j]);
                return false;
            }
        }
    } else if (dataStatus == 0x0C)
    {
        uint8_t p_len  = receicedData[11];
        uint8_t anchor = 12 + p_len;
        for (uint8_t j = 0; j &amp;lt; 3; j++)
        {
            uint8_t offset = anchor + j;
            if (receicedData[offset] != rear_check[j])
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;check failed!, front[%d]: rec:%c\n&amp;quot;, j, receicedData[j]);
                return false;
            }
        }
    } else {
        for (uint8_t j = 0; j &amp;lt; 3; j++)
        {
            uint8_t offset = 12 + j;
            if (receicedData[offset] != rear_check[j])
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;check failed!, front[%d]: rec:%c\n&amp;quot;, j, receicedData[j]);
                return false;
            }
        }
    }

    return true;
}


/**
 * @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;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 1,  m_rx_buf_spi[1]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 2,  m_rx_buf_spi[2]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 3,  m_rx_buf_spi[3]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 4,  m_rx_buf_spi[4]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 5,  m_rx_buf_spi[5]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 36, m_rx_buf_spi[36]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 37, m_rx_buf_spi[37]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 38, m_rx_buf_spi[38]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 39, m_rx_buf_spi[39]);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, 40, m_rx_buf_spi[40]);
        /*
        for (uint8_t i = 39; i &amp;gt; 0; i--)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, i, m_rx_buf_spi[i]);
        }
        for (uint8_t i = 0; i &amp;lt; 40; i++)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, i, m_rx_buf_spi[i]);
        }
        */
        bool checkResult = check_completeness(m_rx_buf_spi);

        if (! checkResult)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;check failed!\n&amp;quot;);
            return;
        }
        /**
         * @brief Begin to transport data
         * 
         */
        g_null_status = false;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Pass data checking\n&amp;quot;);
        uint8_t statusAction =  m_rx_buf_spi[7];
        
        switch (statusAction)
        {
            /** The first datagram **/
            case 0x04:
                receiveData_sendout(m_rx_buf_spi);
                send_datagram_start();
                break;
            /** Other datagrams **/
            case 0x08:
                /** Finish last advertiser, prepare a new advertiser for this sending **/
                set_if_terCurrentAdvertiser(true);
                receiveData_sendout(m_rx_buf_spi);
                send_datagram_start();
                break;
            /** ack **/
            case 0x10:
                /** Finish last advertiser, prepare a new advertiser for this sending **/
                set_if_terCurrentAdvertiser(true);
                receiveHeader_sendout(m_rx_buf_spi);
                send_ack_start();
                break;
            /** source fin **/
            case 0x40:
                /** Finish last advertiser, prepare a new advertiser for this sending **/
                set_if_terCurrentAdvertiser(true);
                receiveHeader_sendout(m_rx_buf_spi);
                send_fin_start();
                break;
            /** dst fin **/
            case 0x80:
                /** Finish last advertiser, prepare a new advertiser for this sending **/
                set_if_terCurrentAdvertiser(true);
                receiveHeader_sendout(m_rx_buf_spi);
                send_fin_start();
                break;
            case 0xD0:
                advertiser_disableAndFlush(); // Finishing the current advertiser 
                break;
            default:
                break;
        }
    }
}

void spis_start(void)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;spis_start\n&amp;quot;);

    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(&amp;amp;spis, &amp;amp;spis_config, spis_event_handler));
        
    while (SWITCH2SPI)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;free: %d\n&amp;quot;, g_null_status);
        uint8_t   *   initArr;
        if (g_null_status)
        {
            initArr = (uint8_t *) malloc (sizeof(uint8_t) * 4);
            if (!initArr)
            {
                return;
            }
            initArr[0] = 0x01;
            initArr[1] = 0x02;
            initArr[2] = 0x03;
            initArr[3] = 0x04;
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;size: %d\n&amp;quot;, strlen(initArr));
            spis_setfrom_slave(initArr, 4); /** Initilization,  filling characters */
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;anchor5\n&amp;quot;);
        } 
        //nrf_delay_ms(10);
        set_transData();
        //nrf_delay_ms(10);
        uint8_t * t_rx_buf_spi = (uint8_t *) malloc(sizeof(uint8_t) * BROADCASRLEN);
        if (!t_rx_buf_spi)
        {
            return;
        }
        memset(t_rx_buf_spi, 0, BROADCASRLEN);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;anchor2\n&amp;quot;);
        spis_xfer_done = false;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;free: %d\n&amp;quot;, g_null_status);
       // uint8_t testArr[3] = {&amp;#39;2&amp;#39;, &amp;#39;3&amp;#39;, &amp;#39;4&amp;#39;};
       __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;m_tx_buf_spi: %d\n&amp;quot;, m_tx_buf_spi[0]);
        APP_ERROR_CHECK(nrfx_spis_buffers_set(&amp;amp;spis, m_tx_buf_spi, m_tx_length, m_rx_buf_spi, BROADCASRLEN));
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;m_tx_buf_spi: %d\n&amp;quot;, m_tx_buf_spi[3]);
          for (uint8_t i = 0; i &amp;lt; 40; i++)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;Transfer completed. Received[%d]: %X \n&amp;quot;, i, m_rx_buf_spi[i]);
        }
        while (!spis_xfer_done)
        {
          //  __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;anchor3\n&amp;quot;);
            (void)sd_app_evt_wait();;
            bsp_board_led_invert(BSP_BOARD_LED_0);
        }
        //    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;anchor4\n&amp;quot;);
        bsp_board_led_invert(BSP_BOARD_LED_1);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;anchorX3\n&amp;quot;);
        
        /**
         * @brief Construct a new free object
         * No matter what happend, it should free m_tx_buf_spi
         */
        free(m_tx_buf_spi);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;anchorX37\n&amp;quot;);
        m_tx_buf_spi = NULL;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;anchorX37B\n&amp;quot;);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, &amp;quot;anchor3\n&amp;quot;);
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The whole code here&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why cannot log all the printing data when receiving from the SPI?</title><link>https://devzone.nordicsemi.com/thread/343337?ContentTypeID=1</link><pubDate>Tue, 14 Dec 2021 09:19:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44b7e648-d3c4-4bef-be4d-eb06b2df5c76</guid><dc:creator>lgs</dc:creator><description>[quote userid="75734" url="~/f/nordic-q-a/82711/why-cannot-log-all-the-printing-data-when-receiving-from-the-spi/343328#343328"]as using a &amp;quot;slow&amp;quot; peripheral like UART&amp;nbsp;&lt;strong&gt;with&amp;nbsp;&lt;/strong&gt;a fast one like SPI is likely to print bad data like this.[/quote]
&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The peripheral is also SPI, do you mean should I adjust phase and polarity parameters?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Gaosheng&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why cannot log all the printing data when receiving from the SPI?</title><link>https://devzone.nordicsemi.com/thread/343328?ContentTypeID=1</link><pubDate>Tue, 14 Dec 2021 08:49:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76c4399c-c849-43b6-9481-348d526790d9</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The issues you have with printing seems to be because you&amp;#39;re trying to print UART messages in an SPI interrupt. Please try adding these prints after the event and interrupt is completed instead, as using a &amp;quot;slow&amp;quot; peripheral like UART&amp;nbsp;&lt;strong&gt;with&amp;nbsp;&lt;/strong&gt;a fast one like SPI is likely to print bad data like this.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>