LORA Transmission via NRF52832 DK returns error -11

I am using the LORA Drivers provided by zephyr for testing my SX1762 lora module with NRF52833 Development Kit. I am able to initialize and configure the LORA Peripherals. but when I am trying to send the buffer over LORA, I am coming up with error code -11 which suggests there is no contexts.

This is my main code:

int lora_configure(const struct device *dev, bool transmit)
{
    int ret;
    struct lora_modem_config config;

    config.frequency = 865100000; //916800000;
    config.bandwidth = BW_125_KHZ;
    config.datarate = SF_10;
    config.preamble_len = 8;
    config.coding_rate = CR_4_5;
    config.tx_power = 4;
    config.iq_inverted = false;
    config.public_network = false;
    config.tx = transmit;

    ret = lora_config(dev, &config);
    if (ret < 0) {
        printk("LoRa device configuration failed");
        return false;
    }
    return(true);
}
int main(void)
{
    const struct device *dev_lora;
    int ret=0;
    int bytes;
    nrf_gpio_cfg_output(AN_SW1);
    nrf_gpio_cfg_output(AN_SW2);
       
    nrf_gpio_pin_set(AN_SW1);
    nrf_gpio_pin_clear(AN_SW2);
    printk("LoRa Point to Point Communications Example\n");
    // Setup LoRa Radio Device:
    dev_lora = DEVICE_DT_GET(DT_ALIAS(lora0));
    if (!device_is_ready(dev_lora)) {
        printk("%s: device not ready\n", dev_lora->name);
        return -1;
    }
    printk("%s: SPI Initialised\n", dev_lora->name);

    if (lora_configure(dev_lora, TRANSMIT)) {
        printk("LoRa Device Tx Configured\n");
    } else {
        return -1;
        printk("LoRa Device Tx Config Failed\n");
    }

    while (1) {
        ret = lora_test_cw(dev_lora,865100000,4,3);
        if (ret < 0) {
            printk("LoRa Test Fail :[%d]\n",ret);
        } else {
            printk("LoRa Test Success\n");
        }
        k_msleep(1000);
        // Transmit data
        ret = lora_send(dev_lora, data_tx, sizeof(data_tx));
        if (ret < 0) {
            printk("LoRa send failed:[%d]\n",ret);
        } else {
            bytes = sizeof(data_tx);
            printk("XMIT %d bytes: ", bytes);
            for (uint16_t i = 0; i < bytes; i++)
                printk("0x%02x ",data_tx[i]);
            printk("\n");
        }
        k_msleep(2000);
    }
    return 0;
}
This is my functions from my lora driver
int sx12xx_lora_send(const struct device *dev, uint8_t *data,
             uint32_t data_len)
{
    struct k_poll_signal done = K_POLL_SIGNAL_INITIALIZER(done);
    struct k_poll_event evt = K_POLL_EVENT_INITIALIZER(
        K_POLL_TYPE_SIGNAL,
        K_POLL_MODE_NOTIFY_ONLY,
        &done);
    uint32_t air_time;
    int ret;

    /* Validate that we have a TX configuration */
    if (!dev_data.tx_cfg.frequency) {
        return -EINVAL;
    }

    ret = sx12xx_lora_send_async(dev, data, data_len, &done);
    if (ret < 0) {
        return ret;
    }

    /* Calculate expected airtime of the packet */
    air_time = Radio.TimeOnAir(MODEM_LORA,
                   dev_data.tx_cfg.bandwidth,
                   dev_data.tx_cfg.datarate,
                   dev_data.tx_cfg.coding_rate,
                   dev_data.tx_cfg.preamble_len,
                   0, data_len, true);
    LOG_DBG("Expected air time of %d bytes = %dms", data_len, air_time);

    /* Wait for the packet to finish transmitting.
     * Use twice the tx duration to ensure that we are actually detecting
     * a failed transmission, and not some minor timing variation between
     * modem and driver.
     */
    ret = k_poll(&evt, 1, K_MSEC(2 * air_time));
    if (ret < 0) {
        LOG_ERR("Packet transmission failed!");
        if (!modem_release(&dev_data)) {
            /* TX done interrupt is currently running */
            k_poll(&evt, 1, K_FOREVER);
        }
    }
    return ret;
}

int sx12xx_lora_send_async(const struct device *dev, uint8_t *data,
               uint32_t data_len, struct k_poll_signal *async)
{
    /* Ensure available, freed by sx12xx_ev_tx_done */
    if (!modem_acquire(&dev_data)) {
        return -EBUSY;
    }

    /* Store signal */
    dev_data.operation_done = async;

    Radio.SetMaxPayloadLength(MODEM_LORA, data_len);

    Radio.Send(data, data_len);

    return 0;
}
static bool modem_release(struct sx12xx_data *data)
{
    /* Increment atomic so both acquire and release will fail */
    if (!atomic_cas(&data->modem_usage, STATE_BUSY, STATE_CLEANUP)) {
        return false;
    }
    /* Put radio back into sleep mode */
    Radio.Sleep();
    /* Completely release modem */
    data->operation_done = NULL;
    atomic_clear(&data->modem_usage);
    return true;
}
static inline bool modem_acquire(struct sx12xx_data *data)
{
    return atomic_cas(&data->modem_usage, STATE_FREE, STATE_BUSY);
}
int sx12xx_lora_test_cw(const struct device *dev, uint32_t frequency,
			int8_t tx_power,
			uint16_t duration)
{
	/* Ensure available, freed in sx12xx_ev_tx_done */
	if (!modem_acquire(&dev_data)) {
		return -EBUSY;
	}

	Radio.SetTxContinuousWave(frequency, tx_power, duration);
	return 0;
}
Error Number is defined as:
#define EAGAIN 11       /**< No more contexts */
#define EBUSY 16        /**< Mount device busy */
Error Logs:
LoRa Test Success
00> LoRa send failed:[-16]
00> LoRa Test Fail :[-16]
00> [00:15:58.939,605] <dbg> sx12xx_common: sx12xx_lora_send: Expected air time of 10 bytes = 289ms
00> [00:16:00.384,704] <err> sx12xx_common: Packet transmission failed!
00> EINVAL[22] EBUSY[16]
00> LoRa send failed:[-11]
When probing the SCK, MISO, MOSI and other pins they are valid, and I am able get desired results.
Related