📄 stm32f10x_adc.lst
字号:
862 * Return : The new state of ADC software start injected conversion (SET or RESET).
863 *******************************************************************************/
864 FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx)
865 {
866 FlagStatus bitstatus = RESET;
867
868 /* Check the status of JSWSTRT bit */
869 if ((ADCx->CR2 & CR2_JSWSTRT_Set) != (u32)RESET)
870 {
871 /* JSWSTRT bit is set */
872 bitstatus = SET;
873 }
874 else
875 {
876 /* JSWSTRT bit is reset */
877 bitstatus = RESET;
878 }
879 /* Return the JSWSTRT bit status */
880 return bitstatus;
881 }
882
883 /*******************************************************************************
884 * Function Name : ADC_InjectedChannelConfig
885 * Description : Configures for the selected ADC injected channel its corresponding
886 * rank in the sequencer and its sample time.
887 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
888 * - ADC_Channel: the ADC channel to configure.
889 * This parameter can be one of the following values:
890 * - ADC_Channel_0: ADC Channel0 selected
891 * - ADC_Channel_1: ADC Channel1 selected
892 * - ADC_Channel_2: ADC Channel2 selected
893 * - ADC_Channel_3: ADC Channel3 selected
894 * - ADC_Channel_4: ADC Channel4 selected
895 * - ADC_Channel_5: ADC Channel5 selected
896 * - ADC_Channel_6: ADC Channel6 selected
897 * - ADC_Channel_7: ADC Channel7 selected
898 * - ADC_Channel_8: ADC Channel8 selected
899 * - ADC_Channel_9: ADC Channel9 selected
900 * - ADC_Channel_10: ADC Channel10 selected
901 * - ADC_Channel_11: ADC Channel11 selected
902 * - ADC_Channel_12: ADC Channel12 selected
903 * - ADC_Channel_13: ADC Channel13 selected
904 * - ADC_Channel_14: ADC Channel14 selected
905 * - ADC_Channel_15: ADC Channel15 selected
906 * - ADC_Channel_16: ADC Channel16 selected
907 * - ADC_Channel_17: ADC Channel17 selected
908 * - Rank: The rank in the injected group sequencer. This parameter
909 * must be between 1 to 4.
910 * - ADC_SampleTime: The sample time value to be set for the
911 * selected channel.
912 * This parameter can be one of the following values:
913 * - ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
914 * - ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
915 * - ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles
916 * - ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles
917 * - ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles
918 * - ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles
919 * - ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles
920 * - ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles
921 * Output : None
922 * Return : None
923 *******************************************************************************/
924 void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, u8 ADC_Channel, u8 Rank, u8 ADC_SampleTime)
925 {
926 u32 tmpreg1 = 0, tmpreg2 = 0;
927 u8 tmpreg3 = 0;
928
929 /* Check the parameters */
930 assert_param(IS_ADC_CHANNEL(ADC_Channel));
931 assert_param(IS_ADC_INJECTED_RANK(Rank));
932 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
933
934 /* if ADC_Channel_10 ... ADC_Channel_17 is selected */
935 if (ADC_Channel > ADC_Channel_9)
936 {
937 /* Get the old register value */
938 tmpreg1 = ADCx->SMPR1;
939 /* Calculate the mask to clear */
940 tmpreg2 = (u32)SMPR1_SMP_Set << (3*(ADC_Channel - 10));
941 /* Clear the old discontinuous mode channel count */
942 tmpreg1 &= ~tmpreg2;
943 /* Calculate the mask to set */
944 tmpreg2 = (u32)ADC_SampleTime << (3*(ADC_Channel - 10));
945 /* Set the discontinuous mode channel count */
946 tmpreg1 |= tmpreg2;
947 /* Store the new register value */
948 ADCx->SMPR1 = tmpreg1;
949 }
950 else /* ADC_Channel include in ADC_Channel_[0..9] */
951 {
952 /* Get the old register value */
953 tmpreg1 = ADCx->SMPR2;
954 /* Calculate the mask to clear */
955 tmpreg2 = (u32)SMPR2_SMP_Set << (3 * ADC_Channel);
956 /* Clear the old discontinuous mode channel count */
957 tmpreg1 &= ~tmpreg2;
958 /* Calculate the mask to set */
959 tmpreg2 = (u32)ADC_SampleTime << (3 * ADC_Channel);
960 /* Set the discontinuous mode channel count */
961 tmpreg1 |= tmpreg2;
962 /* Store the new register value */
963 ADCx->SMPR2 = tmpreg1;
964 }
965
966 /* Rank configuration */
967 /* Get the old register value */
968 tmpreg1 = ADCx->JSQR;
969 /* Get JL value: Number = JL+1 */
970 tmpreg3 = (u8)((tmpreg1 & (u32)~JSQR_JL_Reset)>> 20);
971 /* Calculate the mask to clear: ((Rank-1)+(4-JL-1)) */
972 tmpreg2 = (u32)JSQR_JSQ_Set << (5 * ((Rank + 3) - (tmpreg3 + 1)));
973 /* Clear the old JSQx bits for the selected rank */
974 tmpreg1 &= ~tmpreg2;
975 /* Calculate the mask to set: ((Rank-1)+(4-JL-1)) */
976 tmpreg2 = (u32)ADC_Channel << (5 * ((Rank + 3) - (tmpreg3 + 1)));
977 /* Set the JSQx bits for the selected rank */
978 tmpreg1 |= tmpreg2;
979 /* Store the new register value */
980 ADCx->JSQR = tmpreg1;
981 }
982
983 /*******************************************************************************
984 * Function Name : ADC_InjectedSequencerLengthConfig
985 * Description : Configures the sequencer length for injected channels
986 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
987 * - Length: The sequencer length.
988 * This parameter must be a number between 1 to 4.
989 * Output : None
990 * Return : None
991 *******************************************************************************/
992 void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, u8 Length)
993 {
994 u32 tmpreg1 = 0;
995 u8 tmpreg2 = 0;
996
997 /* Check the parameters */
998 assert_param(IS_ADC_INJECTED_LENGTH(Length));
999
1000 /* Get the old register value */
1001 tmpreg1 = ADCx->JSQR;
1002 /* Clear the old injected sequnence lenght JL bits */
1003 tmpreg1 &= JSQR_JL_Reset;
1004 /* Set the injected sequnence lenght JL bits */
1005 tmpreg2 = Length - 1;
1006 tmpreg1 |= (u32)tmpreg2 << 20;
1007 /* Store the new register value */
1008 ADCx->JSQR = tmpreg1;
1009 }
1010
1011 /*******************************************************************************
1012 * Function Name : ADC_SetInjectedOffset
1013 * Description : Set the injected channels conversion value offset
1014 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
1015 * - ADC_InjectedChannel: the ADC injected channel to set its
1016 * offset.
1017 * This parameter can be one of the following values:
1018 * - ADC_InjectedChannel_1: Injected Channel1 selected
1019 * - ADC_InjectedChannel_2: Injected Channel2 selected
1020 * - ADC_InjectedChannel_3: Injected Channel3 selected
1021 * - ADC_InjectedChannel_4: Injected Channel4 selected
1022 * - Offset: the offset value for the selected ADC injected channel
1023 * This parameter must be a 12bit value.
1024 * Output : None
1025 * Return : None
1026 *******************************************************************************/
1027 void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, u8 ADC_InjectedChannel, u16 Offset)
1028 {
1029 /* Check the parameters */
1030 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
1031 assert_param(IS_ADC_OFFSET(Offset));
1032
1033 /* Set the selected injected channel data offset */
1034 *((u32 *)((*(u32*)&ADCx) + ADC_InjectedChannel)) = (u32)Offset;
1035 }
1036
1037 /*******************************************************************************
1038 * Function Name : ADC_GetInjectedConversionValue
1039 * Description : Returns the ADC injected channel conversion result
1040 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
1041 * - ADC_InjectedChannel: the converted ADC injected channel.
1042 * This parameter can be one of the following values:
1043 * - ADC_InjectedChannel_1: Injected Channel1 selected
1044 * - ADC_InjectedChannel_2: Injected Channel2 selected
1045 * - ADC_InjectedChannel_3: Injected Channel3 selected
1046 * - ADC_InjectedChannel_4: Injected Channel4 selected
1047 * Output : None
1048 * Return : The Data conversion value.
1049 *******************************************************************************/
1050 u16 ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, u8 ADC_InjectedChannel)
1051 {
1052 /* Check the parameters */
1053 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
1054
1055 /* Returns the selected injected channel conversion data value */
1056 return (u16) (*(u32*) (((*(u32*)&ADCx) + ADC_InjectedChannel + JDR_Offset)));
1057 }
1058
1059 /*******************************************************************************
1060 * Function Name : ADC_AnalogWatchdogCmd
1061 * Description : Enables or disables the analog watchdog on single/all regular
1062 * or injected channels
1063 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
1064 * - ADC_AnalogWatchdog: the ADC analog watchdog configuration.
1065 * This parameter can be one of the following values:
1066 * - ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on
1067 * a single regular channel
1068 * - ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on
1069 * a single injected channel
1070 * - ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog
1071 * watchdog on a single regular or injected channel
1072 * - ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on
1073 * all regular channel
1074 * - ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on
1075 * all injected channel
1076 * - ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog
1077 * on all regular and injected channels
1078 * - ADC_AnalogWatchdog_None: No channel guarded by the
1079 *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -