Lora-net / sx126x_driver

Driver for SX126x radio
BSD 3-Clause Clear License
115 stars 37 forks source link

example code #12

Open sumitadep002 opened 2 months ago

sumitadep002 commented 2 months ago

Dear maintainer, i have succefully configured low level read, reset, write and wakeup drivers for my platform Last thing i want to know are there any examples available for this library?

ademgolcuk42 commented 1 month ago

I wrote the "hal driver" as below, but although the rf module goes into "sleep" and "stand_by" modes, I cannot switch it to rx and tx modes. What could be the reason?

sx126x_hal_status_t sx126x_hal_write(LoRa context, const uint8_t command, const uint16_t command_length, const uint8_t *data, const uint16_t data_length) { HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_RESET); sx126x_status_t drmFrekans; for(int i=0;i<command_length;i++) { veri= command[i]; drmFrekans=HAL_SPI_Transmit(context->hSPIx, &veri, 1, 1000); }

if(data_length>0)
{
    for(int i=0;i<data_length;i++)
        {
            veri= data[i];
            drmFrekans=HAL_SPI_Transmit(context->hSPIx, &veri, 1, 1000);
        }
}
HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_SET);
return drmFrekans;

}

/sx126x_hal_status_t sx126x_hal_write(LoRa context, const uint8_t command, const uint16_t command_length, const uint8_t data, const uint16_t data_length) { //sx126x_get_busy(context->hSPIx);

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, 1);
sx126x_status_t drmFrekans;
HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_RESET);
drmFrekans=HAL_SPI_Transmit(context->hSPIx, command, command_length, 1000);

while (HAL_SPI_GetState(context->hSPIx) != HAL_SPI_STATE_READY)
{
    kilitTest++;
}

if(data_length>0)
{

    drmFrekans=HAL_SPI_Transmit(&hspi1, data, data_length, 1000);

    while (HAL_SPI_GetState(context->hSPIx) != HAL_SPI_STATE_READY)
        {
            kilitTest++;
        }
}
HAL_GPIO_WritePin(NSS_GPIO_Port, NSS_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, 0);
return drmFrekans;

}*/

sx126x_hal_status_t sx126x_hal_read(LoRa context, const uint8_t command, const uint16_t command_length, uint8_t data, const uint16_t data_length) { //uint8_t commandi = (uint8_t *)command; HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_RESET); HAL_SPI_Transmit(context->hSPIx, command, command_length, 1000); while (HAL_SPI_GetState(context->hSPIx) != HAL_SPI_STATE_READY) ; HAL_SPI_Receive(context->hSPIx, data, data_length, 1000); while (HAL_SPI_GetState(context->hSPIx) != HAL_SPI_STATE_READY) ; HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_SET);

return 0;

}

sx126x_hal_status_t sx126x_hal_reset(LoRa *context) {

HAL_GPIO_WritePin(context->reset_port,context->reset_pin, GPIO_PIN_RESET);
HAL_Delay(1);
HAL_GPIO_WritePin(context->reset_port,context->reset_pin, GPIO_PIN_SET);
return SX126X_HAL_STATUS_OK;

}

sx126x_hal_status_t sx126x_hal_wakeup(LoRa *context) { HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_RESET); HAL_Delay(1); HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_SET); return SX126X_HAL_STATUS_OK; }

opeyrard commented 1 week ago

Hi, Please have a look to https://github.com/Lora-net/SWSD003 for examples. Many thanks, Best regards,