
BUT: i want some fast ADC data, so the arduino "analogRead(A5)" is much too slow. (about 10 ks , i want 800 ks , what should be really no problem for 5 Ms ADC.)
now...tried to do a call to HAL functions , to get fast data from adc....but this i didnt get to any working output.
so: how to do a HAL call , working (!!!) (yes, the "Correct usage of HAL functions in Arduino code" and others i was reading - but there is no working example !! more discussion about sense or nonsense of 32bit cpu in arduino...not very helpful. )
so please, can anybody show me, how to get some working HAL calls to arduino?
here is, what i tried in arduino:
Code: Select all
static void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
GPIO_InitTypeDef GPIO_InitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
/* USER CODE END ADC1_Init 0 */
ADC_ChannelConfTypeDef sConfig;// = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* Enable clock of ADCx peripheral */
__HAL_RCC_ADC1_CLK_ENABLE();
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC12;
PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_DIV6;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
AdcHandle.Instance = ADC1;
// AdcHandle.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
// AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle.Init.ScanConvMode = ADC_SCAN_DISABLE;
AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START;
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle.Init.NbrOfConversion = 1;
if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
/* multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_6;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_4CYCLES_5;
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* Configure GPIO pin of the selected ADC channel */
GPIO_InitStruct.Pin = ADC_CHANNEL_6;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_PIN_0;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE END ADC1_Init 2 */
}
extern "C" void HAL_ADC_ErrorCallback(ADC_HandleTypeDef * )
{
/* In case of ADC error, call main error handler */
Error_Handler();
}
Code: Select all
HAL_ADC_Start(&AdcHandle);
while ((HAL_ADC_GetState(&AdcHandle), HAL_ADC_STATE_READY) == 0);
adval = HAL_ADC_GetValue(&AdcHandle);
