cancel
Showing results for 
Search instead for 
Did you mean: 

I want to send 16-bit numeric 16-channel data measured by ADC with BLE. However, when programming according to the BLE example, the transmitted data is in the form of 8 bits. What is the general way to solve this?

KKIM.6
Senior

I want to send 16-bit, 16-channel data measured by ADC. but I realize BLE is transfering 8bit data. How can I solve this?

my key script is below.

<main.c>

uint16_t DMAo[16];

​ HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);

 HAL_ADC_Start_DMA(&hadc1, (uint32_t*)DMAo, 16);

<custom_app.c>

uint8_t UpdateCharData[247];

uint8_t NotifyCharData[247];

uint32_t DMA32[16];

extern uint16_t DMAo[16];

extern ADC_HandleTypeDef hadc1;

void myTask(void)

 {

if(HAL_GPIO_ReadPin(LD2_GPIO_Port, LD2_Pin))

{

HAL_ADC_Start(&hadc1);

for(int i=0;i<16;i++)

{

DMAf[i] = DMAo[i];

DMA32[i] = DMAo[i];

UpdateCharData[i] = DMA32[i];

}

  Custom_Readwrite_Update_Char();

}

else

{

HAL_ADC_Stop(&hadc1);

}

UTIL_SEQ_SetTask(1 << CFG_TASK_MY_TASK, CFG_SCH_PRIO_0);

 }

void Custom_Readwrite_Update_Char(void)

{

 Custom_STM_App_Update_Char(CUSTOM_STM_READWRITE, (uint8_t *)UpdateCharData);

 return;

}

<custom_stm.c>

tBleStatus Custom_STM_App_Update_Char(Custom_STM_Char_Opcode_t CharOpcode, uint8_t *pPayload)

{

 tBleStatus result = BLE_STATUS_INVALID_PARAMS;

 switch(CharOpcode)

 {

  case CUSTOM_STM_READWRITE:

   result = aci_gatt_update_char_value(CustomContext.CustomAdccHdle,

                     CustomContext.CustomReadwriteHdle,

                     0, /* charValOffset */

                     SizeReadwrite, /* charValueLen */

                     (uint8_t *) pPayload);

   break;

  default:

   break;

 }

 return result;

}

1 ACCEPTED SOLUTION

Accepted Solutions
Muhammed Güler
Senior III

If everything is correct, you should be getting 32 8-bit data.

On the receiving end, you need to convert 2 8-bit data into 1 16-bit data.

uint8_t ReceivingBytes[32];
uint16_t ReceivingData[16];
 
for(uint8_t i=0;i<16;i++)
{
    ReceivingData[i]=ReceivingBytes[2*i] ;
    ReceivingData[i]=ReceivingData[i]<<8 + ReceivingBytes[2*i+1] ;
}
 

View solution in original post

2 REPLIES 2
Muhammed Güler
Senior III

If everything is correct, you should be getting 32 8-bit data.

On the receiving end, you need to convert 2 8-bit data into 1 16-bit data.

uint8_t ReceivingBytes[32];
uint16_t ReceivingData[16];
 
for(uint8_t i=0;i<16;i++)
{
    ReceivingData[i]=ReceivingBytes[2*i] ;
    ReceivingData[i]=ReceivingData[i]<<8 + ReceivingBytes[2*i+1] ;
}
 

Thanks! it is working successfully