**nRF8001 + STM32 microprocessor + ble_HID_keyboard_template (from Arduino)**
I am now trying to port the ble_HID_keyboard_template from the Arduino:
After the reset, I configure the module, sending it all the SETUP messages (from services.h).
After a while, the module responds with:
// 01 04 81 03 00 02 --> DeviceStartedEvent (81), standby mode (03), no error (00), 2 available buffers/credits (02)
which means that it is ready, in the standby state.
Next, if I issue the command "bond":
uint8_t message_start_bonding[] = {0x05,0x10,0x00,0xB4,0x00,0x50};
That is the equivalent to this call in the Arduino code:
lib_aci_bond(180/* in seconds */, 0x0050 /* advertising interval 50ms*/);
However... the reply from the nRF is:
0x84 0x10 0x85
which signals an ACI_STATUS_ERROR_INVALID_PARAMETER (0x85), in response (0x84) to the "bond" (0x10) command.
values B4 and 50 seem to be inside the limits, according to the manual... I also tried some other values... with no success.
*** I FOUND THE ANSWER ***
In acilib.cpp of the Arduino code, we have this:
void acil_encode_cmd_bond(uint8_t *buffer, aci_cmd_params_bond_t *p_aci_cmd_params_bond) {
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_BOND_LEN;
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_BOND;
*(buffer + OFFSET_ACI_CMD_T_BOND + OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_MSB) = (uint8_t)(p_aci_cmd_params_bond->timeout >> 8);
*(buffer + OFFSET_ACI_CMD_T_BOND + OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_LSB) = (uint8_t)(p_aci_cmd_params_bond->timeout);
*(buffer + OFFSET_ACI_CMD_T_BOND + OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_MSB) = (uint8_t)(p_aci_cmd_params_bond->adv_interval >> 8);
*(buffer + OFFSET_ACI_CMD_T_BOND + OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_LSB) = (uint8_t)(p_aci_cmd_params_bond->adv_interval);
}
but when we go to the aci_protocol_defines.h, we find this:
#define OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_LSB 0
#define OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_MSB 1
#define OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_LSB 2
#define OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_MSB 3
so... turns out that the MSB / LSB bytes are swapped !!!
According to the way the function acil_encode_cmd_bond is specified, I find it really confusing. This fact, coupled with the "incomplete" documentation... made me struggle with this issue.
Please, could someone from Nordic verify this issue?
Also, I would suggest also to modify the documentation for the next release:
(I am using nRF8001_PS v1.2)
Commands "connect" and "bond" are really similar... and only in parameter Advinterval of Bond is noted "(LSB/MSB)"... without any other explanation... A few lines describing a bit the order of the bytes, or a small packet example will be very much appreciated.
Pablo.