最近我尝试了带中断的 Sigma Delta ADC。它工作得很好。现在我想删除中断并添加 DMA。但是随后 DMA 不会将任何内容添加到数据指针数组中。
我没有改变任何东西,除了删除中断和添加 DMA。你觉得我接下来应该怎么做?
这些数组为零。我有 9 个 SDADC 用于 SDADC1。3 个 SDADC 用于 SDADC2,5 个 SDADC 用于 SDADC3。
volatile static int16_t SDADC1_Single[9];
volatile static int16_t SDADC2_Single[3];
volatile static int16_t SDADC3_Differential[5];
完整代码:
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;
}