Hello,
I am trying to write some code that sets the BLE Tx power on the nRF52833 SoC.
I have based my code on the sample example code provided at C:\Zypher\v1.7.0\zephyr\samples\bluetooth\hci_pwr_ctrl\src\main.c and in particular in the function set_tx_power().
static result_t bluetooth_set_ble_tx_power( uint8_t handle_type, uint16_t handle, int8_t tx_pwr_lvl ) { struct bt_hci_cp_vs_write_tx_power_level *cp; struct bt_hci_rp_vs_write_tx_power_level *rp; struct net_buf *buf, *rsp = NULL; result_t result = RESULT_ERROR; buf = bt_hci_cmd_create( BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL, sizeof(*cp) ); if ( buf ) { cp = net_buf_add( buf, sizeof(*cp) ); cp->handle = sys_cpu_to_le16( handle ); cp->handle_type = handle_type; cp->tx_power_level = tx_pwr_lvl; result = bt_hci_cmd_send_sync( BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL, buf, &rsp ); if ( result ) { uint8_t reason = rsp ? ((struct bt_hci_rp_vs_write_tx_power_level *) rsp->data)->status : 0; LOG_WRN( "Set Tx power err: %d reason 0x%02x\n", result, reason ); result = RESULT_ERROR; } else { rp = (void *)rsp->data; LOG_INF( "Actual Tx Power: %d\n", rp->selected_tx_power ); net_buf_unref( rsp ); result = RESULT_OK; } } else { LOG_WRN( "Unable to allocate command buffer\n" ); } return result; }
I am seeing the function bt_hci_cmd_send_sync() returning error -5.
Can you please help me find the cause of this error.
Thank you.