I'm sending a command over BLE from the central (Android) to the nRF52832, and receive SPI data back, but in wrong format. How can I convert/display this data as it is.
I expect to receive [1.2 2.2 3.2]
when I send '1'
to the nRF52832. All I get till now is hex data [FF?@]
.
if (p_evt->params.rx_data.p_data[0] == '1') // If the Rx_Central input is '1', ble_nus_data_send the accelerometer data.
{
spim_rx_buffer.AccX = 1.2; // Random dummy data
spim_rx_buffer.AccY = 2.2; // Random dummy data
spim_rx_buffer.AccZ = 3.2; // Random dummy data
for(int i = 0; i < 3; i++)
{
uint16_t len = sizeof(float);
float* spi_p = (float*) &spim_rx_buffer;
err_code = ble_nus_data_send (&m_nus, (uint8_t*)spi_p+i*sizeof(float), &len, m_conn_handle);
}
}
Reading the documentation of ble_nus_data_send helps:
Function for sending a data to the peer.
This function sends the input string as an RX characteristic notification to the peer.
Parameters
[in] p_nus Pointer to the Nordic UART Service structure.
[in] p_data String to be sent.
[in,out] p_length Pointer Length of the string. Amount of sent bytes.
[in] conn_handle Connection Handle of the destination client.
What you do is to cast a float pointer to uint8, thus, you
You could use sprintf to convert your float to a valid string.
Or you try to violate the API (ugly) and convert your float raw data to uint8, meaning that one float results in probably 4 bytes. Now hope that the underlying code does not interpret something as string, for example 0 terminator or so.