新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ARM常用函數(shù)的配置函數(shù)---重點(diǎn)積累

ARM常用函數(shù)的配置函數(shù)---重點(diǎn)積累

作者: 時(shí)間:2016-11-26 來(lái)源:網(wǎng)絡(luò) 收藏

*****************//初始化獨(dú)立看門(mén)狗******************************
********************************************************************
********************************************************************
********************************************************************
void IWDG_Configuration(void)
{


//是能或者失能對(duì)寄存器IWDG_PR和IWDG_RLR
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);

本文引用地址:http://m.butianyuan.cn/article/201611/321622.htm


//選定工作頻率
IWDG_SetPrescaler(IWDG_Prescaler_32);

//設(shè)置重裝載值
IWDG_SetReload(230);


//按照重裝載器的值重裝載IWDG計(jì)數(shù)器的值-----------此動(dòng)作相當(dāng)于“喂狗”
IWDG_ReloadCounter();


//使能IWDG
IWDG_Enable();
}
/ *******************
/
TIM_DeInit(TIM1);//將外設(shè)TIMx寄存器重設(shè)為缺省值
//2、基礎(chǔ)設(shè)置

TIM1_TimeBaseStructure.TIM_Prescaler = 0x0; //預(yù)分頻,此值+1為分頻的除數(shù)得到計(jì)數(shù)周期;
TIM1_TimeBaseStructure.TIM_Period = 0xFFFF;//計(jì)數(shù)周期(即當(dāng)計(jì)數(shù)值達(dá)到“計(jì)數(shù)值”時(shí),剛好用時(shí)一個(gè)計(jì)數(shù)周期)
TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0;//時(shí)鐘因子
TIM1_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //計(jì)數(shù)器模式
//TIM_CounterMode_Dowm向下計(jì)數(shù)
//TIM_CounterMode_CenterAligned1 中心對(duì)齊方式1
// TIM_CounterMode_CenterAligned2 中心對(duì)齊方式2
// TIM_CounterMode_CenterAligned3 中心對(duì)齊方式3

TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure);
// 3、輸出通道設(shè)置

TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
//TIM_OCMode_Timing輸出比較時(shí)間模式(輸出引腳凍結(jié)無(wú)效)
//TIM_OCMode_Active 輸出比較主動(dòng)模式(匹配時(shí)設(shè)置輸出引腳為有效電平,當(dāng)計(jì)數(shù)值為比較/捕獲寄存器值相同時(shí),強(qiáng)制輸出為高平)
TIM_OCMode_Inactive; 輸出比較非主動(dòng)模式 (匹配時(shí)設(shè)置輸出引腳為無(wú)效電平,當(dāng)計(jì)數(shù)值為比較/捕獲寄存器值相同時(shí),強(qiáng)制輸出為低電平)
//TIM_OCMode_Toggle 輸出比較觸發(fā)模式(翻轉(zhuǎn)。當(dāng)計(jì)數(shù)值與比較/捕獲寄存器值相同時(shí),翻轉(zhuǎn)輸出引腳的電平)
//TIM_OCMode_PWM1向上計(jì)數(shù)時(shí),當(dāng)TIMx_CNT < TIMx_CCR*時(shí),輸出電平有效,否則為無(wú)效,
//向下計(jì)數(shù)時(shí),當(dāng)TIMx_CNT > TIMx_CCR*時(shí),輸出電平無(wú)效,否則為有效
//TIM_OCMode_PWM2 ;與PWM1模式相反

TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;

TIM_OC1Init(TIM1,&TIM1_OCInitStructure);

TIM1_OCInitStructure.TIM_Pulse = CCR2_Val;
TIM_OC2Init(TIM1,&TIM1_OCInitStructure);

TIM1_OCInitStructure.TIM_Pulse = CCR3_Val;
TIM_OC3Init(TIM1,&TIM1_OCInitStructure);


TIM1_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM1_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM1_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM1_BDTRInitStructure.TIM_DeadTime = 0x75;
TIM1_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM1_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM1_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;

TIM_BDTRConfig(TIM1,&TIM1_BDTRInitStructure);


TIM_Cmd(TIM1,ENABLE);


TIM_CtrlPWMOutputs(TIM1,ENABLE);
}

////////////AD的配置函數(shù)/////////////////////////////

//時(shí)鐘配置:
// ADCCLK = PCLK2/4

//應(yīng)用配置
voidADC_configuration()
{
ADC_InitTypeDefADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ScanConvMode = ENABLE;
//ADC_ScanConvMode 規(guī)定了模數(shù)轉(zhuǎn)換工作在掃描模式(多通道)還是單次(單通道)模式??梢栽O(shè)置這個(gè)
//問(wèn)ENABLE 或者 DISABLE。
ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;
//ADC_ContinuousConvMode 規(guī)定了模數(shù)轉(zhuǎn)換工作在連續(xù)還是單次模式??梢栽O(shè)置這個(gè)參數(shù)為 ENABLE 或
//DISABLE。
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
//ADC_ExternalTrigConv描述
//ADC_ExternalTrigConv_T1_CC1選擇定時(shí)器 1 的捕獲比較 1 作為轉(zhuǎn)換外部觸發(fā)
//ADC_ExternalTrigConv_T1_CC2選擇定時(shí)器 1 的捕獲比較 2 作為轉(zhuǎn)換外部觸發(fā)
//ADC_ExternalTrigConv_T1_CC3選擇定時(shí)器 1 的捕獲比較 3 作為轉(zhuǎn)換外部觸發(fā)
//ADC_ExternalTrigConv_T2_CC2選擇定時(shí)器 2 的捕獲比較 2 作為轉(zhuǎn)換外部觸發(fā)
//ADC_ExternalTrigConv_T3_TRGO選擇定時(shí)器 3 的 TRGO作為轉(zhuǎn)換外部觸發(fā)
//ADC_ExternalTrigConv_T4_CC4選擇定時(shí)器 4 的捕獲比較 4 作為轉(zhuǎn)換外部觸發(fā)
//ADC_ExternalTrigConv_Ext_IT11選擇外部中斷線(xiàn) 11 事件作為轉(zhuǎn)換外部觸發(fā)
//ADC_ExternalTrigConv_None轉(zhuǎn)換由軟件而不是外部觸Ⅳ?
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;
//ADC_DataAlign描述:
//ADC_DataAlign_RightADC 數(shù)據(jù)右對(duì)齊
//ADC_DataAlign_LeftADC 數(shù)據(jù)左對(duì)齊
ADC_InitStructure.ADC_NbrOfChannel = 1;// 規(guī)定了順序進(jìn)行規(guī)則轉(zhuǎn)換的 ADC 通道的數(shù)目。這個(gè)數(shù)目的取值范圍是 1 到16。
//ADC_NbreOfChannel
ADC_Init(ADC1, &ADC_InitStructure);


ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5);
//(ADC1 或 ADC2,ADC_Channel_X,Rank,ADC_SampleTime);
//規(guī)則組采樣順序。取值范圍 1 到16。
// ADC_SampleTime://ADC_SampleTime_1Cycles5采樣時(shí)間為 1.5 周期
//ADC_SampleTime_7Cycles5采樣時(shí)間為 7.5 周期
//ADC_SampleTime_13Cycles5采樣時(shí)間為 13.5 周期
//ADC_SampleTime_28Cycles5采樣時(shí)間為 28.5 周期
//ADC_SampleTime_41Cycles5采樣時(shí)間為 41.5 周期
//ADC_SampleTime_55Cycles5采樣時(shí)間為 55.5 周期
//ADC_SampleTime_71Cycles5采樣時(shí)間為 71.5 周期
//ADC_SampleTime_239Cycles5 采樣時(shí)間為 239.5 周期

ADC_DMACmd(ADC1, ENABLE);


ADC_Cmd(ADC1, ENABLE);


ADC_ResetCalibration(ADC1);

while(ADC_GetResetCalibrationStatus(ADC1));//等待ADC的校準(zhǔn)寄存器被設(shè)置完畢


ADC_StartCalibration(ADC1);

while(ADC_GetCalibrationStatus(ADC1));


ADC_SoftwareStartConvCmd(ADC1, ENABLE);

AD_value=ADC_GetConversionValue(ADC1);//返回最近一次 ADCx 規(guī)則組的轉(zhuǎn)換結(jié)果
}

void DMA_Configuration(void)
{
DMA_DeInit(DMA_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//定義DMA外設(shè)基地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; // 定義DMA內(nèi)存基地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//外設(shè)作為數(shù)據(jù)傳輸?shù)膩?lái)源(外設(shè)傳到內(nèi)存) DMA_DIR_PeripheralDST——內(nèi)存?zhèn)鞯酵庠O(shè)
DMA_InitStructure.DMA_BufferSize = 3;//連續(xù)轉(zhuǎn)化3個(gè)AD通道值
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外設(shè)寄存器地址不變
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//內(nèi)存寄存器地址遞增
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //外設(shè)數(shù)據(jù)寬度32bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;//內(nèi)存數(shù)據(jù)寬度32bit
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA模式是循環(huán)
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA優(yōu)先級(jí)
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//DMA沒(méi)有設(shè)置內(nèi)存到內(nèi)存?zhèn)鬏?br />DMA_Init(DMA_Channel1, &DMA_InitStructure);

DMA_Cmd(DMA_Channel1, ENABLE);
}

//RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
void DAC_Configuration(void)
{
DAC_InitTypeDef DAC_InitStructure;

DAC_InitStructure.DAC_Trigger=DAC_Trigger_Software;//DAC觸發(fā)方式為軟件控制
DAC_InitStructure.DAC_WaveGeneration=DAC_WaveGeneration_None;//不從DAC端口產(chǎn)生波形
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bits8_0; //8位DA波形生成模式
DAC_InitStructure.DAC_OutputBuffer=DAC_OutputBuffer_Enable;//使能DAC輸出緩沖器
//用上面參數(shù)初始化DAC通道1
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_1, ENABLE);//使能DAC通道1
DAC_Init(DAC_Channel_2, &DAC_InitStructure);//用上面參數(shù)初始化DAC通道1
DAC_Cmd(DAC_Channel_2, ENABLE);//使能DAC通道2
DA的使用方式:
DAC_SetChannel2Data(DAC_Align_12b_L, DAC_data);//設(shè)置DAC通道1為12位且數(shù)據(jù)左對(duì)齊模式
DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);//使能DAC通道1的軟件觸發(fā)方式,轉(zhuǎn)換一次
DAC_SetChannel1Data(DAC_Align_12b_L, DAC_data);//設(shè)置DAC通道1為12位且數(shù)據(jù)左對(duì)齊模式
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);//使能DAC通道1的軟件觸發(fā)方式,轉(zhuǎn)換一次
}


上一頁(yè) 1 2 下一頁(yè)

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉