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

SPI long data transfer

Hello Everyone,

I am newbie to nordic BLE environment. This maybe a silly question.

Currently I am using nrf51 DK with SDK11, S130.

Data to be sent through SPI:

I checked the example code in SDK11, and there is example code and m_tx_buf is variable for sending data, but not sure how should I send all the data mentioned in above image. Data is very long to be sent as data is of type long long and m_tx_buf is of type const uin8_t *. 

This link embed entire initialisation values of LCD init command in one buffer, do I need to follow the same?

Thanks in advance.

Parents Reply Children
  • Hi,

    Assuming you still want a separate write for the address you can do it like this (assuming blocking mode):

    void sendDataToSPI(uint8_t address, unsigned long datagram)
    {
        static length = sizeof(address); // 1
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &address, length, m_rx_buf, length));
    
        length = sizeof(datagram); // 4
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, (uint8_t *)&datagram, length, m_rx_buf, length));
    }

    If you don't want to send the address in a separate transaction (I don't see any reason why), then you can make an array containing both so that you only have one transaction.

  • Hi Einar,

    Thanks for the reply again.

    Is this correct if I transfer complete date in one go?

    
    void sendSPI(unsigned long datagram) 
    { 
        static int length= sizeof(datagram); 
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, (uint8_t *) &datagram, length, m_rx_buf, length)); 
    }
    .
    
    .
    int main()
    {
        sendSPI(0x80000008); sendSPI(0xEC0100C5); sendSPI(0xB0011F05); sendSPI(0xAC002710); sendSPI(0x900401C8); sendSPI(0xB2061A80); sendSPI(0xB1007530); sendSPI(0xA6001388); sendSPI(0xA7004E20); sendSPI(0xA0000001); sendSPI(0x21000000);
    }
    
    

    One more question:

    if (m_rx_buf[0] != 0) { NRF_LOG_PRINTF(" Received: %x\r\n",m_rx_buf); 

    this part is printing 

    0>  Received: 20000034

    0>  Received: 20000034

    0>  Received: 20000034

    0>  Received: 20000034

    No matter what's the data send by SPI.

  • Hi,

    That looks OK.

    The way you print the RX buffer you print it as if it was a variable, but the number looks like it is an address (in RAM). So most likely you are just printing a pointer address. How have you declared m_rx_buf?

  • Hi,

    The m_rx_buf is declared as the following:

    #define SPI_INSTANCE  0 /**< SPI instance index. */
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
    static volatile bool spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */
    long long MISO = 0x8000000008;
    #define TEST_STRING "0x8000000008"
    
    unsigned char val0, val1, val2, val3, val4;
    
    static uint8_t       m_tx_buf[] = {0x80};           /**< TX buffer. */
    static uint8_t       m_rx_buf[sizeof(TEST_STRING)+1];    /**< RX buffer. */
    static uint8_t m_length = sizeof(m_tx_buf);        /**< Transfer length. */
    
    
    void spi_event_handler(nrf_drv_spi_evt_t const * p_event)
    {
        spi_xfer_done = true;
        //NRF_LOG_PRINTF(" Transfer completed.\r\n");
    	  //NRF_LOG_PRINTF(" address: %x %x %x %x\n", val3, val2, val1, val0);
    
        if (m_rx_buf[0] != 0)
        {
            NRF_LOG_PRINTF(" Received: %x\r\n",m_rx_buf);
        }
    }

  • I see. Then it is as I assumed, you just print the address of the buffer. A simple way to print the buffer as a hexadecimal string is to use NRF_LOG_HEXDUMP_INFO.

Related