/* SysTick end of count event each 1ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
UART_Init();
/* Configure DMA2 to transfer data from SDADC data register to embedded SRAM */
DMA2_Config();
/* POT_SDADC channel5P (in Single Ended Zero Reference mode) configuration using
injected conversion with continuous mode enabled */
SDADC1_Config();
/* Configure TIM3 as trigger for SDADC conversion */
TIM13_Config();
TIM_Cmd(TIM13, ENABLE);
/* Set the SDADC divider: The SDADC should run @6MHz */
/* If Sysclk is 72MHz, SDADC divider should be 12 */
RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div48);
/* Select External reference: The reference voltage selection is available
only in SDADC1 and therefore to select the VREF for SDADC2/SDADC3, SDADC1
clock must be already enabled */
SDADC_VREFSelect(POT_SDADC_VREF);
/* Enter initialization mode */
SDADC_InitModeCmd(POT_SDADC, ENABLE);
SDADCTimeout = SDADC_INIT_TIMEOUT;
/* wait for INITRDY flag to be set */
while((SDADC_GetFlagStatus(POT_SDADC, SDADC_FLAG_INITRDY) == RESET) && (--SDADCTimeout != 0));
if(SDADCTimeout == 0)
{
/* INITRDY flag can not set */
return 1;
}
/* Analog Input configuration conf0: use single ended zero reference */
SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEZeroReference;
SDADC_AINStructure.SDADC_Gain = POT_SDADC_GAIN;
SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA;
SDADC_AINStructure.SDADC_Offset = 0;
SDADC_AINInit(POT_SDADC, SDADC_Conf_0, &SDADC_AINStructure);
/* Enable DMA transfer for injected conversions */
SDADC_DMAConfig(POT_SDADC, SDADC_DMATransfer_Injected,ENABLE);
/* Exit initialization mode */
SDADC_InitModeCmd(POT_SDADC, DISABLE);
/* configure calibration to be performed on conf0 */
SDADC_CalibrationSequenceConfig(POT_SDADC, SDADC_CalibrationSequence_1);
/* start POT_SDADC Calibration */
SDADC_StartCalibration(POT_SDADC);
/* Set calibration timeout: 5.12 ms at 6 MHz in a single calibration sequence */
SDADCTimeout = SDADC_CAL_TIMEOUT;
/* wait for POT_SDADC Calibration process to end */
while((SDADC_GetFlagStatus(POT_SDADC, SDADC_FLAG_EOCAL) == RESET) && (--SDADCTimeout != 0));
if(SDADCTimeout == 0)
{
/* EOCAL flag can not set */
return 2;
}
/* Enable end of injected conversion interrupt */
// SDADC_ITConfig(POT_SDADC, SDADC_IT_JEOC, ENABLE);
/* Start a software start conversion */
// SDADC_SoftwareStartInjectedConv(POT_SDADC);
// SDADC_SoftwareStartConv(POT_SDADC);