cancel
Showing results for 
Search instead for 
Did you mean: 

Why does the DMA not read the Sigma Delta ADC?

DMårt
Lead

I have sigma delta 16-bit ADC enabled.

It works great with regular interrupt. No problem there, but when I'm trying to use DMA with Sigma Delta ADC, then nothing happens. It will only be zeros.

I have 9 SDADC zero referenze on SDADC1, 3 SDADC zero reference on SDADC1 and 5 SDADC differential on SDADC3.

These arrays will only have zeros included:

SDADC1_Single[9]

SDADC2_Single[3]

SDADC3_Differential[5]

Why does this happen?

volatile static int16_t SDADC1_Single[9];
volatile static int16_t SDADC2_Single[3];
volatile static int16_t SDADC3_Differential[5];
static float SDADC_Single_Calibration_Gain[12] = {0};
static float SDADC_Single_Calibration_Bias[12] = {0};
static float SDADC_Differential_Calibration_Gain[5] = {0};
static float SDADC_Differential_Calibration_Bias[5] = {0};
 
void STM32_PLC_Start_Analog_Input(TIM_HandleTypeDef* htim12, TIM_HandleTypeDef* htim13, TIM_HandleTypeDef* htim16, SDADC_HandleTypeDef* hsdadc1, SDADC_HandleTypeDef* hsdadc2, SDADC_HandleTypeDef* hsdadc3) {
	/*
	 * For TIM12, TIM13 and TIM16
	 * Timer clock: 48 Mhz
	 * Prescaler: 0
	 * Counter: 48000 (0xbb80)
	 * Update frequency: 1000 Hz
	 */
	HAL_TIM_OC_Start(htim13, TIM_CHANNEL_1); /* TIM13 is trigger source for SDADC1 */
	HAL_TIM_OC_Start(htim12, TIM_CHANNEL_1); /* TIM12 is trigger source for SDADC2 */
	HAL_TIM_OC_Start(htim16, TIM_CHANNEL_1); /* TIM16 is trigger source for SDADC3 */
	if (HAL_SDADC_CalibrationStart(hsdadc1, SDADC_CALIBRATION_SEQ_1) != HAL_OK)
		Error_Handler();
	if (HAL_SDADC_CalibrationStart(hsdadc2, SDADC_CALIBRATION_SEQ_1) != HAL_OK)
		Error_Handler();
	if (HAL_SDADC_CalibrationStart(hsdadc3, SDADC_CALIBRATION_SEQ_1) != HAL_OK)
		Error_Handler();
	if (HAL_SDADC_PollForCalibEvent(hsdadc1, HAL_MAX_DELAY) != HAL_OK)
		Error_Handler();
	if (HAL_SDADC_PollForCalibEvent(hsdadc2, HAL_MAX_DELAY) != HAL_OK)
		Error_Handler();
	if (HAL_SDADC_PollForCalibEvent(hsdadc3, HAL_MAX_DELAY) != HAL_OK)
		Error_Handler();
	if(HAL_SDADC_InjectedStart_DMA(hsdadc1, (uint32_t*)SDADC1_Single, 9) != HAL_OK)
		Error_Handler();
	if(HAL_SDADC_InjectedStart_DMA(hsdadc2, (uint32_t*)SDADC2_Single, 3) != HAL_OK)
		Error_Handler();
	if(HAL_SDADC_InjectedStart_DMA(hsdadc3, (uint32_t*)SDADC3_Differential, 5) != HAL_OK)
		Error_Handler();
}
 
/* Get ADC0 to ADC11 */
float STM32_PLC_Analog_Input_ADC_Get(uint8_t i) {
	return SDADC_Single_Calibration_Gain[i]*((float)STM32_PLC_Analog_Input_ADC_Get_Raw(i)) + SDADC_Single_Calibration_Bias[i];
}
 
/* Get raw ADC0 to ADC11 */
uint16_t STM32_PLC_Analog_Input_ADC_Get_Raw(uint8_t i) {
	if(i < 9)
		return SDADC1_Single[i] + 0x8000;
	else
		return SDADC2_Single[i-9] + 0x8000;
}
 
/* Set calibration ADC0 to ADC11 */
void STM32_PLC_Analog_Input_ADC_Set_Calibration(uint8_t i, float min_value, float max_value, float bias_value) {
	SDADC_Single_Calibration_Gain[i] = (max_value - min_value) / (0xFFFF);
	SDADC_Single_Calibration_Bias[i] = bias_value;
}
 
/* Get DADC0 to DADC4 */
float STM32_PLC_Analog_Input_DADC_Get(uint8_t i) {
	return SDADC_Differential_Calibration_Gain[i]*((float)STM32_PLC_Analog_Input_DADC_Get_Raw(i)) + SDADC_Differential_Calibration_Bias[i];
}
 
/* Get raw DADC0 to DADC4 */
int16_t STM32_PLC_Analog_Input_DADC_Get_Raw(uint8_t i) {
	return SDADC3_Differential[i];
}
 
/* Set calibration DADC0 to DADC4 */
void STM32_PLC_Analog_Input_DADC_Set_Calibration(uint8_t i, float min_value, float max_value, float bias_value) {
	SDADC_Differential_Calibration_Gain[i] = (max_value - min_value) / (0xFFFF);
	SDADC_Differential_Calibration_Bias[i] = bias_value;
}

STM32MP151AAC3 custom board with STM32-OS as operating system: https://github.com/DanielMartensson/STM32-Computer
0 REPLIES 0