cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F373 SDADC1 trigger by Timer 19

enrico
Associate
Posted on November 07, 2014 at 11:22

Hi all!

This is my first project with ST micro. I have evaluation board stm32373c-eval. I have generated low level code with STM32cubeMX. I want start SDADC1 triggered by TIMER19 but the SDADC1 start always (not triggered by timer) After I copied from an example of ST ''PressureMeasurement'' that do the same. I have comment the generated code and use this: But always the same, I trigger with GPIO in interrupt for debug. I use Library pack (not legacy). Anyone have some ideas? Need other informations? Thanks at all. Enrico


void
SDADC1_Config(
void
)

{

hsdadc1.Instance = SDADC1;

hsdadc1.Init.ReferenceVoltage = SDADC_VREF_EXT;

hsdadc1.Init.IdleLowPowerMode = SDADC_LOWPOWER_NONE;

hsdadc1.Init.FastConversionMode = SDADC_FAST_CONV_DISABLE;

hsdadc1.Init.SlowClockMode = SDADC_SLOW_CLOCK_DISABLE;


/* -1- Initialise the SDADC */

if
(HAL_SDADC_Init(&hsdadc1) != HAL_OK)

{}


/* -2- Prepare the channel configuration */

ConfParamStruct.CommonMode = SDADC_COMMON_MODE_VSSA;

ConfParamStruct.Gain = SDADC_GAIN_1;

ConfParamStruct.InputMode = SDADC_INPUT_MODE_SE_OFFSET;

ConfParamStruct.Offset = 0x00000000;

if
(HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_0, &ConfParamStruct) != HAL_OK) {Error_Handler();}


/* associate channel 0 to the configuration 0 */

if
(HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_0, SDADC_CONF_INDEX_0) != HAL_OK) {Error_Handler();}


/* select channel 0 for injected conversion and not for continuous mode */

if
(HAL_SDADC_InjectedConfigChannel(&hsdadc1, SDADC_CHANNEL_0, SDADC_CONTINUOUS_CONV_OFF) != HAL_OK) {Error_Handler();}


/* Select external trigger for injected conversion */

if
(HAL_SDADC_SelectInjectedTrigger(&hsdadc1, SDADC_EXTERNAL_TRIGGER) != HAL_OK) {Error_Handler();}


/* Select timer 19 channel 2 as external trigger and rising edge */

if
(HAL_SDADC_SelectInjectedExtTrigger(&hsdadc1, SDADC_EXT_TRIG_TIM19_CC2, SDADC_EXT_TRIG_RISING_EDGE) != HAL_OK) {Error_Handler();}


/* Start Calibration in polling mode */

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 injected conversion in interrupt mode */

if
(HAL_SDADC_InjectedStart_IT(&hsdadc1) != HAL_OK) {Error_Handler();}


/* Start the TIMER's Channel */

if
(HAL_TIM_PWM_Start_IT(&htim19, TIM_CHANNEL_2) != HAL_OK) {Error_Handler();}

}


void
MX_TIM19_User_Init(
void
)

{

/*##-4- Configure TIMER ###################################################*/

/* Enable the timer clock */

__TIM19_CLK_ENABLE();


/* Configure the timer in PWM mode */

htimInstance = TIM19;

htimInit.ClockDivision = 0;

htimInit.CounterMode = TIM_COUNTERMODE_UP;

htimInit.Period = 0xe10; 
/* Freq = 72Mhz/3600 = 20KHz */

htimInit.Prescaler = 0;

HAL_TIM_PWM_Init(&htim19);


sConfigOC.OCMode = TIM_OCMODE_PWM1;

sConfigOC.Pulse = 0x708;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

HAL_TIM_PWM_ConfigChannel(&htim19, &sConfigOC, TIM_CHANNEL_2);


/* Peripheral interrupt init*/

HAL_NVIC_SetPriority(TIM19_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(TIM19_IRQn);

1 REPLY 1
Posted on February 26, 2015 at 16:34

Hicontiero.enrico,

Regarding your issue, after double check your source code thru SDADC1_Config, confirm that it is the good configuration to be done to manage Conversion of the SDADC using an external Timer. Now, about issue, I think I have reproduce your issue by remove a part of mandatory code. Here is the software code that you need to have up to the software code that you have already. Please verify that your example works better by adding the Conversion callback management like that :

__IO uint32_t InjConvValue = 0;
__IO uint32_t InjChannel = 0;
/**
* @brief Injected conversion complete callback. 
* @note In interrupt mode, user has to read conversion value in this function
using HAL_SDADC_InjectedGetValue or HAL_SDADC_InjectedMultiModeGetValue.
* @param hsdadc : SDADC handle.
* @retval None
*/
void HAL_SDADC_InjectedConvCpltCallback(SDADC_HandleTypeDef* hsdadc)
{
InjConvValue = HAL_SDADC_InjectedGetValue(hsdadc, (uint32_t *) &InjChannel);
}

For your information, if a conversion have been done (mean HAL_SDADC_InjectedConvCpltCallback is called), you will need to Get the Conversion Value to prevent multiple call of HAL_SDADC_InjectedConvCpltCallback() which can explain the comportment that you have observed.

Hope that solve your issue, Regards, Heisenberg.