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
  • 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.

  • 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.

Reply
  • 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.

Children
Related