2019-10-14 09:42 AM
Hey there,
I'm using a STM32H742 Eval Boards to read analog data with the ADC with DMA. I want to do multiple measuremts very rapidly.
In the first measurment the ADC reads a couple Zeros (see plot, note: plote is bit older and has multiple measurments with Zeros in it. That Problem got solved by altering the SCB_InvalidateDCache_by_Addr function)
My ADC Init:
static void MX_ADC3_Init(void)
{
/* USER CODE BEGIN ADC3_Init 0 */
/* USER CODE END ADC3_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC3_Init 1 */
/* USER CODE END ADC3_Init 1 */
/** Common config
*/
hadc3.Instance = ADC3;
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV8;
hadc3.Init.Resolution = ADC_RESOLUTION_16B;
hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc3.Init.LowPowerAutoWait = DISABLE;
hadc3.Init.ContinuousConvMode = ENABLE;
hadc3.Init.NbrOfConversion = 1;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc3.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc3) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_3;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC3_Init 2 */
/* USER CODE END ADC3_Init 2 */
}
The ADC gets called in his function :
void Sweep(void)
{
iadc_data_callback=0;
HAL_GPIO_WritePin( SWEEP_IN_GPIO_Port, SWEEP_IN_Pin, GPIO_PIN_SET);
if(HAL_ADC_Start_DMA(&hadc3,(uint32_t*) &ADC3_sample_buf[numberofSweeps- 1], ADC_DATA_ARRAY_SIZE))
Error_Handler();
}
ab the Callback functio looks like this
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
/* Prevent unused argument(s) compilation warning */
if (hadc == &hadc3)
{
HAL_GPIO_WritePin( SWEEP_IN_GPIO_Port, SWEEP_IN_Pin, GPIO_PIN_RESET);
/* Invalidate complete data cache to get the updated content of the SRAM of the
* ADC converted data buffer */
SCB_InvalidateDCache_by_Addr((uint32_t *) &ADC3_sample_buf[0],(30*ADC_DATA_ARRAY_SIZE*sizeof(uint16_t)) ); /* size is bytes */
// SCB_InvalidateDCache_by_Addr((uint32_t *) &ADC3_sample_buf[0],sizeof(ADC3_sample_buf) ); /* size in storage units */
iadc_data_callback |= 0x10;
numberofSweeps--;
if (numberofSweeps)
{
Sweep();
}
else
{
CDC_Transmit_HS( (uint8_t*) ADC3_sample_buf, sizeof(ADC3_sample_buf));
}
}
}
I have no Idea where the error comes from.