STM32F3 Dual ADC mode?

An area to discuss ARM specific problems and examples

Moderator: Benj

Post Reply
User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Contact:

STM32F3 Dual ADC mode?

Post by fotios »

Hi everyone and Happy New Year.

I try to enable the Dual ADC mode on STM32F303 without success.
In dual mode, the ADC1 and ADC2 work simultaneously, and the ADC2 is the slave of ADC1.
The result of conversion is stored into the "ADC12_CDR" 32-bit register, of which the higher word "RDATA_SLV" contains the slave ADC result and the lower word "RDATA_MST" contains the master ADC result.
In my application is useful the "Regular Simultaneous Mode" given that the ADC1 and ADC2 have the same configuration exactly, and detect similar signals. (I suppose that the ADC conversions will be executed faster?)
To this, the "ADC12_CCR.DUAL" (bits 4:0 of ADCx_CCR register) should get "00110".
Here is my simple C code line:

Code: Select all

ADC12_CCR.DUAL = 0x06;
The FC compiler returns the error that the "ADC12_CCR" is undeclared.
C:\Users\FOTIOS\DOCUME~1\FLOW_C~1>arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Os -DSTM32 -DSTM32F3 -DSTM32F303xE -DUSE_HAL_DRIVER -DHSE_VALUE=24000000 -IC:\PROGRA~2\FLOWCO~1\COMPIL~1\STARM\batch\..\stm32cubeF3\Drivers\CMSIS\Include -IC:\PROGRA~2\FLOWCO~1\COMPIL~1\STARM\batch\..\stm32cubeF3\Drivers\CMSIS\Device\ST\STM32F3xx\Include -IC:\PROGRA~2\FLOWCO~1\COMPIL~1\STARM\batch\..\stm32cubeF3\Drivers\STM32F3xx_HAL_Driver\Inc -IC:\PROGRA~2\FLOWCO~1\COMPIL~1\STARM\batch\..\stm32cubeF3\Drivers\STM32F3xx_HAL_Driver\Inc\Legacy -IC:\PROGRA~2\FLOWCO~1\COMPIL~1\STARM\batch\..\inc -fmessage-length=0 -fdata-sections -ffunction-sections -w -c "ADC_STM.c" -o "ADC_STM_STM32F303xE_24000000\ADC_STM.o"
ADC_STM.c: In function 'main':
ADC_STM.c:1728:2: error: 'ADC12_CCR' undeclared (first use in this function)
// Calculation:
^
ADC_STM.c:1728:2: note: each undeclared identifier is reported only once for each function it appears in
Error(s) in build

C:\Program Files (x86)\Flowcode 7\compilers\STARM\batch\stm32comp.bat reported error code 1
Here is also a copy from the code generated by STM32CubeIDE, when the dual mode is selected:

Code: Select all

  /** Configure the ADC multi-mode 
  */
  multimode.Mode = ADC_DUALMODE_REGSIMULT;
  multimode.DMAAccessMode = ADC_DMAACCESSMODE_12_10_BITS;
  multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;
  if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
  {
    Error_Handler();
  }
Thanks for any help
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2049
Joined: Tue Jan 17, 2012 10:07 am
Contact:

Re: STM32F3 Dual ADC mode?

Post by LeighM »

Hi,
To access the ADC12 common control register you need to do this ...

Code: Select all

ADC12_COMMON->CCR = 0x06;
Hope that helps,
Leigh

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Contact:

Re: STM32F3 Dual ADC mode?

Post by fotios »

Hi Leigh

Yes, FC compiles successfully with this equation. No errors. Thanks.

It remains, how I could read back the 32-bit data register "ADC12_CDR".
E.g.

Code: Select all

ADC1_IN = ADC12_CDR & 0xFFFF
ADC2_IN = ADC12_CDR & 0xFFFF0000 
ADC2_IN = ADC2_IN >> 16
?

Thanks again
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2049
Joined: Tue Jan 17, 2012 10:07 am
Contact:

Re: STM32F3 Dual ADC mode?

Post by LeighM »

Code: Select all

ADC1_IN = ADC12_COMMON->CDR & 0xFFFF;
ADC2_IN = ADC12_COMMON->CDR & 0xFFFF0000;
ADC2_IN = ADC2_IN >> 16;

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Contact:

Re: STM32F3 Dual ADC mode?

Post by fotios »

Thanks,

I will try it in a couple of hours and will let you know (lunchtime in Greece :))
I have to modify my variables.
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Contact:

Re: STM32F3 Dual ADC mode?

Post by fotios »

Thanks
Last edited by fotios on Fri Jan 10, 2020 10:27 am, edited 3 times in total.
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2049
Joined: Tue Jan 17, 2012 10:07 am
Contact:

Re: STM32F3 Dual ADC mode?

Post by LeighM »

To return the value from a macro …

Code: Select all

FCR_RETVAL = ADC12_COMMON->CDR;
To copy the value into a Flowcode global variable named ADC12_IN …

Code: Select all

FCV_ADC12_IN = ADC12_COMMON->CDR;

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Contact:

Re: STM32F3 Dual ADC mode?

Post by fotios »

Thanks!
Should I replace the:

Code: Select all

FCR_RETVAL = HAL_ADC_GetValue(&MX_ADC1_HANDLE);
with

Code: Select all

FCR_RETVAL = ADC12_COMMON->CDR;
And then to add into the same code window the line:

Code: Select all

FCV_ADC12_IN = ADC12_COMMON->CDR;
?
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2049
Joined: Tue Jan 17, 2012 10:07 am
Contact:

Re: STM32F3 Dual ADC mode?

Post by LeighM »

Hi,
The previous post was just demonstrating how to read the device registers into Flowcode variables using C code.

For your application, which uses the ADC dual read mode, to setup the ADC and read values etc., you will need to either access the device registers directly (seems you have made some progress on that with the datasheet)
or use the ST HAL API. e.g. Cube generated code or your own code based on the published HAL API
(see C:\Program Files (x86)\Flowcode7\Compilers\starm\stm32cubef3\Drivers\STM32F3xx_HAL_Driver)

Things can get messy if you try mixing HAL code and direct register access.

I’ve not yet used dual mode myself so don’t have any pointers on that (without doing a lot of reading)

The C code device register definitions can be found here …
C:\Program Files (x86)\Flowcode7\Compilers\starm\stm32cubef3\Drivers\CMSIS\Device\ST\STM32F3xx\Include

Hope that helps,
Leigh

Post Reply