2020-12-21 04:04 PM
Hi!
I want to report a bug.
I tried SDADC and I found a bug.
Also it should stand "Multi mode" not "Mulimode" and the STM32CubeIDE 1.5.0 (I'm using) missing calibration options in the STM32CubeIDE project starter.
To solve this issue. Write this code inside the "SDADC_init()" function
// Multi mode for SDADC1 and SDADC3
if (HAL_SDADC_InjectedMultiModeConfigChannel(&hsdadc1, SDADC_MULTIMODE_SDADC1_SDADC3) != HAL_OK)
{
Error_Handler();
}
Example:
/**
* @brief SDADC1 Initialization Function
* @param None
* @retval None
*/
static void MX_SDADC1_Init(void)
{
/* USER CODE BEGIN SDADC1_Init 0 */
/* USER CODE END SDADC1_Init 0 */
SDADC_ConfParamTypeDef ConfParamStruct = {0};
/* USER CODE BEGIN SDADC1_Init 1 */
/* USER CODE END SDADC1_Init 1 */
/** Configure the SDADC low power mode, fast conversion mode,
slow clock mode and SDADC1 reference voltage
*/
hsdadc1.Instance = SDADC1;
hsdadc1.Init.IdleLowPowerMode = SDADC_LOWPOWER_NONE;
hsdadc1.Init.FastConversionMode = SDADC_FAST_CONV_DISABLE;
hsdadc1.Init.SlowClockMode = SDADC_SLOW_CLOCK_DISABLE;
hsdadc1.Init.ReferenceVoltage = SDADC_VREF_VDDA;
hsdadc1.InjectedTrigger = SDADC_SOFTWARE_TRIGGER;
if (HAL_SDADC_Init(&hsdadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure the Injected Mode
*/
if (HAL_SDADC_SelectInjectedDelay(&hsdadc1, SDADC_INJECTED_DELAY) != HAL_OK)
{
Error_Handler();
}
if (HAL_SDADC_SelectInjectedTrigger(&hsdadc1, SDADC_SOFTWARE_TRIGGER) != HAL_OK)
{
Error_Handler();
}
if (HAL_SDADC_InjectedConfigChannel(&hsdadc1, SDADC_CHANNEL_4|SDADC_CHANNEL_8
|SDADC_CHANNEL_6, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
{
Error_Handler();
}
/** Set parameters for SDADC configuration 0 Register
*/
ConfParamStruct.InputMode = SDADC_INPUT_MODE_SE_ZERO_REFERENCE;
ConfParamStruct.Gain = SDADC_GAIN_1;
ConfParamStruct.CommonMode = SDADC_COMMON_MODE_VSSA;
ConfParamStruct.Offset = 0;
if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_0, &ConfParamStruct) != HAL_OK)
{
Error_Handler();
}
/** Set parameters for SDADC configuration 1 Register
*/
ConfParamStruct.InputMode = SDADC_INPUT_MODE_DIFF;
if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_1, &ConfParamStruct) != HAL_OK)
{
Error_Handler();
}
/** Configure the Injected Channel
*/
if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_4, SDADC_CONF_INDEX_0) != HAL_OK)
{
Error_Handler();
}
/** Configure the Injected Channel
*/
if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_8, SDADC_CONF_INDEX_1) != HAL_OK)
{
Error_Handler();
}
/** Configure the Injected Channel
*/
if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_6, SDADC_CONF_INDEX_1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SDADC1_Init 2 */
// Multi mode for SDADC1 and SDADC3
if (HAL_SDADC_InjectedMultiModeConfigChannel(&hsdadc1, SDADC_MULTIMODE_SDADC1_SDADC3) != HAL_OK)
{
Error_Handler();
}
// Calibration
if (HAL_SDADC_CalibrationStart(&hsdadc1, SDADC_CALIBRATION_SEQ_1) != HAL_OK) {
Error_Handler();
}
// Pool for the end of calibration
if (HAL_SDADC_PollForCalibEvent(&hsdadc1, HAL_MAX_DELAY) != HAL_OK) {
Error_Handler();
}
// Start interrupt mode
if (HAL_SDADC_InjectedStart_IT(&hsdadc1) != HAL_OK) {
Error_Handler();
}
/* USER CODE END SDADC1_Init 2 */
}
Also for using multiple interrupts for the SDADC (In this case SDADC1 and SDADC3). Please use this code as callback function for the NVIC interrupt. Here i have 3 inputs from SDADC1 and 2 inputs from SDADC3.
// When we got a measurement
uint32_t CHANNEL = 4;
uint16_t SD_ADC[6] = {0};
void HAL_SDADC_InjectedConvCpltCallback(SDADC_HandleTypeDef *hsdadc){
// CHANNEL will be 4, 6, 8 but randomly
// SD_ADC for SDADC1 = [SDADC1_IN4, 0, SDADC1_IN6, SDADC3_IN6, SDADC1_IN8, SDADC3_IN8];
if(hsdadc->Instance == SDADC1){
SD_ADC[CHANNEL - 4] = HAL_SDADC_InjectedGetValue(hsdadc, &CHANNEL);
}else if(hsdadc->Instance == SDADC3){
SD_ADC[CHANNEL - 4 + 1] = HAL_SDADC_InjectedGetValue(hsdadc, &CHANNEL);
}
}
Screenshot of the bug:
Solved! Go to Solution.
2020-12-22 06:24 AM
Hi @Daniel Mårtensson ,
Thank you for your feedback,
This is reported internally and it will be fixed as soon as possible.
Thanks again
2020-12-22 12:54 AM
Hi @Daniel Mårtensson ,
Thank you for your feedback.
Could you please share your .ioc file.
What I understand that the bug is "Mulimode" should be "Multi mode", is that right ?
Could you add more details.
Thanks again
Houssem
2020-12-22 05:52 AM
As you can see in the picture above, I cannot select "Mulimode" because it's disabled. It should not be disabled. It should be an option to select SDADC3 from SDADC1. Therefore, I had to add this manually. Also "Mulimode" is spelled wrong.
But the SDADC works perfectly! I think there is a lack of examples how to use SDADC in STM32.
// Multi mode for SDADC1 and SDADC3
if (HAL_SDADC_InjectedMultiModeConfigChannel(&hsdadc1, SDADC_MULTIMODE_SDADC1_SDADC3) != HAL_OK)
{
Error_Handler();
}
2020-12-22 06:24 AM
Hi @Daniel Mårtensson ,
Thank you for your feedback,
This is reported internally and it will be fixed as soon as possible.
Thanks again