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

regarding spi communication nrf52840 with sx1276

hello,

i am using nrf52840 dvk with sx1276 lora modules and trying to  read my device address using spi i am just calling the below function in main

uint8_t spiCommandData[2];
uint8_t spiReadData[2];

static unsigned char RFM_Read()
{
unsigned char RFM_Data;

spiCommandData[0]=0x42 & 0x7f;
spiCommandData[1]=0;

nrf_gpio_pin_clear(SPI_SS_PIN);

nrf_drv_spi_transfer(&spi, ( uint8_t* )&spiCommandData, 2,( uint8_t* ) &spiReadData, 2);


nrf_gpio_pin_set(SPI_SS_PIN);

// rfm_spi_uninit();


return spiReadData[1]; 
}

is this correct method to use spi or AM i doing something wrong

thanks and regards

manikandan v

  • Hi,

    Normally, the SPI device will output data after you have written the command/address, while the SPI peripheral in the nRF52840 will start filling the RX buffer at the same time you are writing data from the TX buffer. If you set the RX length to 2 as you have done in your code, the SPI will not read any bytes after the TX buffer output is completed, the RX buffer will be filled at the same time. If you want to read 2 bytes after TX is done, you need to increase the RX length to 4 bytes, and ignore the 2 first bytes in the RX buffer.

    Best regards,
    Jørgen

Related