cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with sx1262 module

ademgolcuk
Associate

I am trying to switch between modes (standby, rx, tx, sleep) in the sx1262 module. While switching, I pay attention to the figure below in the datasheet of the lora module. For example, to switch from SX126X_STANDBY_CFG_RC mode to RX mode, I use the command sx126x_set_rx(&myLoRa, 0). Then I use the command sx126x_get_status(&myLoRa, &radio_status) to check if the module has switched to rx mode but the cmd_status value is read as "SX126X_CMD_STATUS_CMD_EXEC_FAILURE" and the chip_mode value is read as "standby".

modes.png

1 REPLY 1
ademgolcuk
Associate

The read and write functions are as follows. Does anyone have any information about the problem?

 

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_hal_status_t status = SX126X_HAL_STATUS_OK;

HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_RESET);

 

if (HAL_SPI_Transmit(context->hSPIx, command, command_length, HAL_MAX_DELAY)!= HAL_OK) {

status = SX126X_HAL_STATUS_ERROR;

}

 

while (HAL_SPI_GetState(context->hSPIx) != HAL_SPI_STATE_READY);

 

 

if(data != NULL && data_length > 0)

{

if (HAL_SPI_Transmit(context->hSPIx, data, data_length, HAL_MAX_DELAY)!= HAL_OK) {

status = SX126X_HAL_STATUS_ERROR;

}

while (HAL_SPI_GetState(context->hSPIx) != HAL_SPI_STATE_READY);

}

HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_SET);

 

return status;

}

 

 

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)

{

sx126x_hal_status_t status = SX126X_HAL_STATUS_OK;

HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_RESET);

 

if (HAL_SPI_Transmit(context->hSPIx, command, command_length, HAL_MAX_DELAY) != HAL_OK) {

status = SX126X_HAL_STATUS_ERROR;

}

 

while (HAL_SPI_GetState(context->hSPIx) != HAL_SPI_STATE_READY);

 

if (data != NULL && data_length > 0) {

if (HAL_SPI_Receive(context->hSPIx, data, data_length, HAL_MAX_DELAY) != HAL_OK) {

status = SX126X_HAL_STATUS_ERROR;}

}

while (HAL_SPI_GetState(context->hSPIx) != HAL_SPI_STATE_READY);

HAL_GPIO_WritePin(context->NSS_port, context->NSS_pin, GPIO_PIN_SET);

 

return status;

}