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

How to set SPI tx rx butter size for nrf_drv_spi_transfer ?

Hi Sir 

The product is nrf52840 and SDK15, If I'd want to do following SPI operation  ( CS to L ---> MOSI data {0x60, 0x00, 0x00, 0x11} ---> CS to H )

1. How to setup nrf_drv_spi_transfer ? Is it like this? 

uint8_t tx_buf[4] = {0x60, 0x00, 0x00, 0x11} ;

uint8_t  rx_buf = 0x0;

nrf_drv_spi_transfer(&spi, tx_buf, 4, rx_buf, 0);   is it correct ??

and Is it working too?

uint8_t tx_buf1[2] = {0x60, 0x00} ;

uint8_t tx_buf2[2] = {0x00, 0x11} ;

nrf_drv_spi_transfer(&spi, tx_buf1, 2, rx_buf, 0);  

nrf_drv_spi_transfer(&spi, tx_buf2, 2, rx_buf, 0);  

2. Could l set SPI data width to 16bit ?

3. The SPI peripheral device is BIG ENDIAN device, Should I set bit_order to NRF_DRV_SPI_BIT_ORDER_LSB_FIRST ?

Thanks.

Parents
  • 1. You should take a look at the example in in SDK at /examples/peripheral/spi/main.c. It gives a fully working function including all the setups required (which is a bit more than your code shows). Also rx_buf needs to be an array, its length ofc bigger than 0. But take a look at the example, verything done there right.

    2. Unless you change the drivers itself, no.

    3. No, leave it at the default value NRF_DRV_SPI_BIT_ORDER_MSB_FIRST. Big Endian is MSB first.

Reply
  • 1. You should take a look at the example in in SDK at /examples/peripheral/spi/main.c. It gives a fully working function including all the setups required (which is a bit more than your code shows). Also rx_buf needs to be an array, its length ofc bigger than 0. But take a look at the example, verything done there right.

    2. Unless you change the drivers itself, no.

    3. No, leave it at the default value NRF_DRV_SPI_BIT_ORDER_MSB_FIRST. Big Endian is MSB first.

Children
No Data
Related