你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F030K6 TIM15 问题

[复制链接]
憨客鱼 提问时间:2021-4-1 14:15 / 未解决
我用TIM3 ADC DMA 做了一个AD 采集,因为我TIM3 打算用做其他用途,所以准备把TIM3 换成TIM15 但是 一换成TIM15 DMA 中断就进不去了,我就查找原因,加了 TIM15 中断,但是 TIM15 中断确也进不去,请问哪位大侠知道是什么原因么

void Adc_Init(void)
{
        Adc_IO_Init();
        Tim3_Init();
        DMA_Bsp_Init();
        ADC_Bsp_Init();
}

//*******************************************************************************
//
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//*******************************************************************************
void Adc_IO_Init(void)
{
       
        GPIO_InitTypeDef        GPIO_InitStructure;       
/* GPIOC Periph clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  /* Configure PC8 and PC9 in output pushpull mode */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_2| GPIO_Pin_5| GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

}



//*******************************************************************************
//
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//*******************************************************************************
void ADC_Bsp_Init( void )
{

    ADC_InitTypeDef  ADC_InitStructure;  

                /*ÉèÖÃADC·ÖƵÒò×ÓΪ4 ,ADC×î´óʱ¼ä²»Äܳ¬¹ý14M*/
                RCC_ADCCLKConfig(RCC_ADCCLK_PCLK_Div4);       
       
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

                ADC_StructInit(&ADC_InitStructure);
                ADC_InitStructure.ADC_Resolution=ADC_Resolution_12b;
//                ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;//??AD???????
                ADC_InitStructure.ADC_ContinuousConvMode=DISABLE;//??AD???????       
                ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;       
                ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_T15_TRGO;//?????????
//                ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConvEdge_None;//?????????       
                ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;//???????????????????
//                ADC_InitStructure.ADC_ScanDirection=ADC_ScanDirection_Backward;
                ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; //CH0-18       
            ADC_Init(ADC1, &ADC_InitStructure);
       
        //   /* ADC DMA request in circular mode */
                ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);

      //ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 0, ADC_SampleTime_28_5Cycles);
                ADC_ChannelConfig(ADC1, ADC_Channel_0|ADC_Channel_2|ADC_Channel_5,  ADC_SampleTime_28_5Cycles);        
       
       
  /* ADC Calibration */
                ADC_GetCalibrationFactor(ADC1);
   ADC_DMACmd(ADC1, ENABLE);
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);     

  /* Wait the ADCEN falg */
  while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
       
                TIM_Cmd(TIM15, ENABLE);               
                DMA_Cmd(DMA1_Channel1, ENABLE);               
               
                 ADC_StartOfConversion(ADC1);

}

//*******************************************************************************
//
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//*******************************************************************************
void Tim3_Init(void)
{

  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;       
        NVIC_InitTypeDef NVIC_InitStructure;       

//     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15, ENABLE);        
//????
  TIM_DeInit(TIM15);
  TIM_TimeBaseStructure.TIM_ClockDivision=0;//48M
  TIM_TimeBaseStructure.TIM_Prescaler=48;//48k 1Tick=1ms
  TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period=1000-1;//10s??
  TIM_TimeBaseStructure.TIM_RepetitionCounter=0;//??RepetitionCounter+1????????
  TIM_TimeBaseInit(TIM15,&TIM_TimeBaseStructure);
//        TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);               
        TIM_SelectMasterSlaveMode(TIM15, TIM_MasterSlaveMode_Enable);                       
  TIM_SelectOutputTrigger(TIM15,TIM_TRGOSource_Update);//TIM15?Update??????TRGO
       

//    TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);//?????? TIM ???,?????1       
       
  TIM_ClearFlag(TIM15,TIM_FLAG_Update); //????????? ????????
       
//  TIM_Cmd(TIM3,ENABLE);//??TIM3       
       
       
        TIM_CtrlPWMOutputs(TIM15,ENABLE);       
  /*  TIM3 ??????*/
   TIM_ITConfig(TIM15,TIM_IT_Update,ENABLE);//?????? TIM ???,?????1               
  NVIC_InitStructure.NVIC_IRQChannel = TIM15_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);               
        NVIC_EnableIRQ(TIM15_IRQn);           
}



//*******************************************************************************
//
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//*******************************************************************************
void DMA_Bsp_Init(void)
{

    DMA_InitTypeDef DMA_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;

    DMA_DeInit(DMA1_Channel1);
                RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

    DMA_InitStructure.DMA_PeripheralBaseAddr = (unsigned int)&ADC1->DR;
//            DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->ADDR11;
    DMA_InitStructure.DMA_MemoryBaseAddr = (unsigned int)&g_usAdcBuff[0];
//        DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC1_addr11;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
    DMA_InitStructure.DMA_BufferSize = NUM_ADC_LENTH;
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

//   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;        
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
//  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;       
       
//   DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
                DMA_InitStructure.DMA_Priority = DMA_Priority_High;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
    DMA_Init(DMA1_Channel1, &DMA_InitStructure);


                NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
                NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
                NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
                NVIC_Init(&NVIC_InitStructure);                       
               
               
    DMA_ITConfig(DMA1_Channel1, DMA_IT_TC|DMA_IT_HT, ENABLE);                               
         
//   DMA_Cmd(DMA1_Channel1, ENABLE);


}



//*******************************************************************************
//
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//*******************************************************************************
void DMA1_Channel1_IRQHandler(void)
{
        unsigned short int i,j;
        unsigned int uiSum;
       
       
    if(DMA_GetITStatus(DMA1_IT_TC1))
    {
        DMA_ClearITPendingBit(DMA1_IT_TC1);                       
                       
                        uiSum =0;
                        for(i=0;i<NUM_ADC_DATA/2;i++)
                        {
                                j=i*3;
                                uiSum = uiSum+g_usAdcBuff[NUM_ADC_LENTH/2+j];                               
                        }
                        uiSum = uiSum>>NUM_ROL_HALF;                       
                        g_usAmp = uiSum;

                        for(i=0;i<NUM_ADC_DATA/2;i++)
                        {
                                j=1+i*3;
                                uiSum = uiSum+g_usAdcBuff[NUM_ADC_LENTH/2+j];                               
                        }
                        uiSum = uiSum>>NUM_ROL_HALF;                       
                        g_usReel = uiSum;
                       
                        for(i=0;i<NUM_ADC_DATA/2;i++)
                        {
                                j = 2+i*3;
                                uiSum = uiSum+g_usAdcBuff[NUM_ADC_LENTH/2+j];                               
                        }
                        uiSum = uiSum>>NUM_ROL_HALF;                       
                        g_usVol = uiSum;
                       
                       
                        GPIO_ResetBits(GPIOB,GPIO_Pin_5);//TEST DEBUG
                }       
                       
                       
    if(DMA_GetITStatus(DMA1_IT_HT1))
    {
        DMA_ClearITPendingBit(DMA1_IT_HT1);

                        uiSum =0;
                        for(i=0;i<NUM_ADC_DATA/2;i++)
                        {
                                j = i*3;
                                uiSum = uiSum+g_usAdcBuff[j];                               
                        }
                        uiSum = uiSum>>NUM_ROL_HALF;                       
                        g_usAmp = uiSum;

                        for(i=0;i<NUM_ADC_DATA/2;i++)
                        {
                                j=1+i*3;
                                uiSum = uiSum+g_usAdcBuff[j];                               
                        }
                        uiSum = uiSum>>NUM_ROL_HALF;                       
                        g_usReel = uiSum;
                       
                        for(i=0;i<NUM_ADC_DATA/2;i++)
                        {
                                j=2+i*3;
                                uiSum = uiSum+g_usAdcBuff[j];                               
                        }
                        uiSum = uiSum>>NUM_ROL_HALF;                       
                        g_usVol = uiSum;

                        GPIO_SetBits(GPIOB,GPIO_Pin_5);//TEST DEBUG                       
    }               
               
}

//*******************************************************************************
//
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//*******************************************************************************
void TIM15_IRQHandler(void)
{
        if(TIM_GetITStatus(TIM15, TIM_IT_Update) == SET)
        {
                TIM_ClearITPendingBit(TIM15,TIM_IT_Update);
               
        }

}


收藏 评论2 发布时间:2021-4-1 14:15

举报

2个回答
xmshao 回答时间:2021-4-1 17:46:37
[看了你的代码,没发现明显异常。你确定是STM32F030K6吗?我试着CubeMX去配置,没发现TIM15啊。然后看数据手册,也没说它有TIM15. 手册有说别的芯片有。Available on STM32F030x8 and STM32F030xBdevices only.但它没有]*

憨客鱼 回答时间:2021-4-1 15:03:42
是我自己搞晕了  STM32F030K6 根本没有TIM15
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版