cancel
Showing results for 
Search instead for 
Did you mean: 

Interfacing SX1262 LoRa module using SPI DMA

Shaktimayee
Associate II

Hi everyone,
I am using STM32F103c8t6 module for transmitting and receiving data in between two SX1262 LoRa module. 
The libraries are found in https://github.com/Lora-net/sx126x_driver/tree/v2.3.2 link and i have successfully transmit and receive data using normal SPI communication but i want to transmit and receive the data using SPI DMA mode but i am unable to do that.
If anyone know about this please guide me regarding this. 

Thank you in advance!!

4 REPLIES 4
Andrew Neil
Super User

The SX1262 neither knows nor cares how the SPI lines get driven - it just requires that they are correct.

So put an analyser on the lines, and compare what happens in your working non-DMA case against your non-working DMA case.

Are you using the exact same hardware in both cases?

 

PS:

Also, have you tried the drivers direct from Semtech?

https://www.semtech.com/products/wireless-rf/lora-connect/sx1262

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Peter BENSCH
ST Employee

@Shaktimayee

And since you're talking about an "STM32F103c8t6 module", I assume it's a Blue Pill?

If so, hardly anyone will be able to help you, as Asian clones have been used there for years. You would be doing yourself a favour to use one of the original, genuine NUCLEO boards instead, for which there is unrestricted support.

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thank you 
Yes, i am using blue pill at transmitter end and receiver end. Yes i am using the driver for sx1262 from semtech.
By following way i am initializing 

init_LoRa_parm();
  sx126x_reset(&LoRa);
  sx126x_init(&LoRa );
  sx126x_set_dio2_as_rf_sw_ctrl(&LoRa, true);
  sx126x_set_dio3_as_tcxo_ctrl(&LoRa, SX126X_TCXO_CTRL_1_8V, 0x00000F);
  sx126x_get_device_errors(&LoRa, &errors);
  printf("before STDBY_XOSC, Errors = 0x%X\r\n", errors);
  sx126x_set_standby(&LoRa, SX126X_STANDBY_CFG_XOSC);
  sx126x_clear_device_errors( &LoRa);
  sx126x_get_device_errors(&LoRa, &errors);
  printf("After STDBY_XOSC, Errors = 0x%X\r\n", errors);
  Radio_init(&LoRa);
  sx126x_clear_irq_status( &LoRa, SX126X_IRQ_ALL );
  sx126x_set_dio_irq_params(
  		  &LoRa, SX126X_IRQ_ALL,
            SX126X_IRQ_TX_DONE | SX126X_IRQ_RX_DONE,
            SX126X_IRQ_NONE, SX126X_IRQ_NONE );

  sx126x_clear_irq_status( &LoRa, SX126X_IRQ_ALL );

and in main loop i am putting the following function

void on_tx_data(void)
{
    sx126x_status_t status;

    // Prepare data
    for (int i = 0; i < 8; i++) {
        tx_buf[i] = counter++;
    }

    // Write buffer with error checking
    status = sx126x_write_buffer(&LoRa, 0, (const uint8_t*)tx_buf, 8);
    if (status != SX126X_STATUS_OK) {
        printf("Write buffer failed: %d\n", status);
        return;
    }

    // Set TX mode with error checking
    status = sx126x_set_tx(&LoRa, 0);
    if (status != SX126X_STATUS_OK) {
        printf("Set TX failed: %d\n", status);
        return;
    }

    // Print transmitted data
    printf("Sent: ");
    for (int i = 0; i < 8; i++) {
        printf("%d ", tx_buf[i]);
    }
    printf("\r\n");
}

where tx_buf is the global variable.
and 

void init_LoRa_parm(void)
{
	txdata[0] = 'M';
	txdata[1] = 'L';
	txdata[2] = 'o';
	txdata[3] = 'R';
	txdata[4] = 'a';

	LoRa.BUSY_port = BUSY_GPIO_Port;
	LoRa.BUSY_pin  = BUSY_Pin;
	LoRa.NSS_port  = NSS_GPIO_Port;
	LoRa.NSS_pin   = NSS_Pin;
	LoRa.RST_port  = RST_GPIO_Port;
	LoRa.RST_pin   = RST_Pin;
	LoRa.DIO1_port = DIO1_GPIO_Port;
	LoRa.DIO1_pin  = DIO1_Pin;

	LoRa.hSPIx     = &hspi1;
}

this is the initialization value.
By taking this guide me to transmit the data over SPI DMA mode.

At least the SPI DMA transmission and reception operation will work on bluepill as the normal transmit and receive operation is occuring frequently.