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.

  • Hi,

    As you write, the SPI driver uses uint8_t, so you must handle it like that. I do not see that as a problem though. You would still provide a pointer to the beginning of the data, so all you should have to do is to cast the pointer and set the length field properly (length in bytes). Lastly you might want to consider the endianess (in case the bytes of your long data type are not transferred in the order you need.)

  • Hello Einar,

    Thank you for your reply. I made this function "sendDataToSPI" which accepts the address and data (as mentioned in the above image). Total 40 bits are transferred via SPI in each data transfer. The first byte is send directly and later 32 byte are split in to 4 byte and sent separately. 

    Is this function Ok?

    void sendDataToSPI(uint8_t address, unsigned long datagram)
    {					
    				APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &address, m_length, m_rx_buf, m_length));
    	      NRF_LOG_PRINTF(" address: %x\r\n",address);
    
    				val0 = (datagram & 0xFF);
    
    				datagram >>= 8;
    				val1 =  (datagram & 0xFF);
    
    				datagram >>= 8;
    				val2 = (datagram & 0xFF);
    
    				datagram >>= 8;
    				val3 =  (datagram & 0xFF);
    	
    				APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &val3, m_length, m_rx_buf, m_length));
            NRF_LOG_PRINTF(" val3: %x\r\n",val3);
    	
    				APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &val2, m_length, m_rx_buf, m_length));
            NRF_LOG_PRINTF(" val2: %x\r\n",val2);
    		
    				APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &val1, m_length, m_rx_buf, m_length));
            NRF_LOG_PRINTF(" val1: %x\r\n",val1);
    	
    				APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &val0, m_length, m_rx_buf, m_length));
            NRF_LOG_PRINTF(" val0: %x\r\n",val0);
    
    
    }

  • Hi,

    Why do you split the transaction up like this? You can send up to 255 bytes in one transfer. Just let the puffer pointer point to the start of the data, and set the length field to a multiple of the bytes you have to send.

Related