2022-05-09 11:31 AM
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;
}
Solved! Go to Solution.
2022-05-10 05:16 AM
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] ;
}
2022-05-10 05:16 AM
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] ;
}
2022-05-11 06:43 AM
Thanks! it is working successfully