SPI not working with SX1262 on NRF52832

I am working on nrf52832 development kit for interfacing SX1262 Lora module via SPI. I have configured SPI 0 as follows:

/* LORA Module */
#define LORA_D101_PIN		24
#define LORA_RFRESET_PIN	05
#define LORA_MISO_PIN		30
#define LORA_MOSI_PIN		29
#define LORA_SCK_PIN		26
#define LORA_NSS_PIN		31

#define SPI_INSTANCE  0                                         /**< SPI instance index. */
const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);   /**< SPI instance. */
uint8_t spi_xfer_done;                                          /**< Flag used to indicate that SPI instance completed the transfer. */

void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
	spi_xfer_done = 1;
}

void spi_init()
{
	uint8_t err_code;

	nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
	spi_config.ss_pin   = NRF_DRV_SPI_PIN_NOT_USED;
	spi_config.miso_pin = LORA_MISO_PIN;
	spi_config.mosi_pin = LORA_MOSI_PIN;
	spi_config.sck_pin  = LORA_SCK_PIN;

	err_code = nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL);
	APP_ERROR_CHECK(err_code);
}

Initially I am trying to read the SX1262_REG_SYNC_WORD register with address 0x0740. As per SX1262 datasheet it's default value will be 0x14. But I am getting the value 0x00. The code is given below.

// Helper function to assert NSS (chip select) low
static void SX1262_Select(void) {
	nrf_drv_gpiote_out_clear(LORA_NSS_PIN);
}

// Helper function to de-assert NSS (chip select) high
static void SX1262_Unselect(void) {
	nrf_drv_gpiote_out_set(LORA_NSS_PIN);
}

uint16_t SX1262_ReadRegister() {
	
	uint8_t command = 0x1D;  		// Read Register Command
	uint8_t addr[2] = {0x07, 0x40};
	uint8_t data[2] = {0, 0};  		// To store the read data
	uint8_t dummy_byte[2] = {0, 0};

	// Unselect the SX1262 (NSS high)
	SX1262_Select();
		
	spi_xfer_done = 0;
	
	nrf_drv_spi_transfer(&spi, &command, 1, NULL, 0);
	while(spi_xfer_done == 0){__WFI();}
	spi_xfer_done = 0;

	nrf_drv_spi_transfer(&spi, addr, 2, NULL, 1);
	while(spi_xfer_done == 0){__WFI();}
	spi_xfer_done = 0;	
				
	nrf_drv_spi_transfer(&spi, NULL, 0, dummy_byte, 1);
	while(spi_xfer_done == 0){__WFI();}
	spi_xfer_done = 0;

	nrf_drv_spi_transfer(&spi, NULL, 0, rx_data, 1);
	while(spi_xfer_done == 0){__WFI();}
	spi_xfer_done = 0;	
			
	if(rx_data[0] != 0x14) {
			
		SX1262_Unselect();
		return 0xFFFF;
	}

    	// Unselect the SX1262 (NSS high)
    	SX1262_Unselect();
	return (data[0]);
}

What will be the issue?

Thanks

Sachin

Parents Reply
  • Hi Vidar,

    Thank you for your reply.

    I have tried allowing the driver to control the CS line. But result was same.

    I am attaching the logic trace of bus lines.

    This is the logic trace where CS line is not configured in SPI driver.

    This is the logic trace where CS line is configured in SPI driver.

    I have tested the LORA module with STM32F4 and Arduino boards and the module is working fine.

     

    Thanks

    Sachin

Children
Related