你的浏览器版本过低,可能导致网站不能正常访问!为了你能正常使用网站功能,请使用这些浏览器。
意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的8位单片机和基于ARM® Cortex®-M0、M0+、M3、M4、M33、M7及A7内核并具备丰富外设选择的32位微控制器及微处理器。关注该话题即可发布文章!
回复:STM32步进电机程序
回复:STM32步进电机程序
RE:STM32步进电机程序
回复:STM32步进电机程序
回复:STM32步进电机程序
回复:STM32步进电机程序
RE:STM32步进电机程序
RE:STM32步进电机程序
回复:STM32步进电机程序
RE:STM32步进电机程序
RE:STM32步进电机程序
GPIO_InitTypeDef GPIO_InitStructure;
ErrorStatus HSIStartUpStatus;
void NVIC_Configuration(void);
void RCC_Configuration(void);
void TIM2_Configuration(void);
void GPIO_Configuration(void);
#define VECT_TAB_RAM" J H4 d/ d. i2 F
int main(void)- N' b# A* D3 z1 d8 p0 j* _2 g
{
#ifdef DEBUG" _ ]8 R8 [3 ?
debug();/*[初始化外围设备指针]*/
#endif, C9 ^, H- K, N8 V* x; r8 R! ], C
RCC_Configuration(); //初始化时钟与复位
NVIC_Configuration();//初始化中断嵌套, O& Z \# g) T5 X) V- M
TIM2_Configuration();//初始化定时器
GPIO_Configuration();
" n& }, `9 y( {& k' o7 H
GPIO_WriteBit(GPIOD, GPIO_Pin_7, (BitAction)(0));. U$ o6 }4 R; G4 |! N8 h# h, L7 b
GPIO_WriteBit(GPIOD, GPIO_Pin_6, (BitAction)(0)); //DCY1 DCY2为00,即Normal %0 DECAY
" R* f( n- \; a1 `2 g" ]& p
GPIO_WriteBit(GPIOE, GPIO_Pin_7, (BitAction)(1));) F! `2 F& m6 m& b2 Y2 p
GPIO_WriteBit(GPIOB, GPIO_Pin_1, (BitAction)(0)); //M1M2为10,即1-2-phase! f O$ F5 O; T2 z5 f
GPIO_WriteBit(GPIOA, GPIO_Pin_4, (BitAction)(0)); //正向旋转$ Q2 c3 D: i+ G% \7 c4 b1 V( D0 [
GPIO_WriteBit(GPIOB, GPIO_Pin_0, (BitAction)(0));
GPIO_WriteBit(GPIOC, GPIO_Pin_5, (BitAction)(1)); //TQ1 TQ2为01,即Current Ratio为50%* y" Y% h9 a( Q7 T2 Q
GPIO_WriteBit(GPIOA, GPIO_Pin_7, (BitAction)(1)); //StepReset位# q% `" @1 M6 g( j
GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(1)); //StepEn 使能位
8 i2 P, ^3 Y8 I& S
while(1)- U! q: z0 F! e4 p9 V
{( ?' A+ t' {- h& r3 Y
}
}6 n# s8 m' `, S$ h) X+ y- X/ g, I
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_7; //PA的3.4.7接CLK,CW/CCW,StepReset6 _# K" s F; w8 T4 L2 V$ ?9 W( i, e- S
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);# A6 N6 j, d# C+ }
GPIO_InitStructure.GPIO_Pin= GPIO_Pin_5 | GPIO_Pin_6; //PA的6.7接Protect和Mo
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4 | GPIO_Pin_5; //PC的4.5接StepEn和TQ2
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;% v! y8 h6 q! W/ T8 }2 ?. \
GPIO_Init(GPIOC,&GPIO_InitStructure);; F7 b6 e `7 T
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1; //PB的0.1接TQ1和M2
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7; //PE7接M1 U1 G6 s8 S' C% ]/ j2 v8 L+ V
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;1 U; w( J& g' P, |& j$ d
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStructure);
. X% \0 x5 d+ k" z O
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6 | GPIO_Pin_7; //PD的67接DCY2和DCY1
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOD,&GPIO_InitStructure);0 a. p+ R; ?9 z, g/ `- C) h( e% z
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;2 K P2 s, o# m1 D
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else 7 y+ T6 t; t2 K! ?
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); ) O* L4 O1 I5 a0 q
#endif
' v9 d2 Y$ I. l \
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //设置TIM2通道输入中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /*配置优先级组*/! z& ?; a# B- w8 I+ J
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; " v: G, h( L/ i
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /*允许TIM2全局中断*/
NVIC_Init(&NVIC_InitStructure);
}+ V/ q a( L: C* ^# G% Y9 x- B
void TIM2_Configuration(void)1 f& o# _" {1 S0 I
{
TIM_SetCounter( TIM2, 0x0000);. a1 c5 L/ H) T) \3 C
TIM_ClearFlag(TIM2, TIM_FLAG_Update); /*清除更新标志位*/
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); //清除TIM2等待中断更新中断标志位
TIM_ARRPreloadConfig(TIM2, ENABLE); /*预装载寄存器的内容被立即传送到影子寄存器 */ d' W4 J! _9 ?
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); //使能TIM2的更新 5 Y* I G! X2 P0 W1 C
( P* C# O. H6 F$ e" L: d
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 120; //设定的最大计数值,计数值到则产生一次中断
TIM_TimeBaseStructure.TIM_Prescaler = 30; //分频
TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 时钟分割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //计数方向向上计数
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);6 z) ?6 c5 f- Y7 w
TIM_Cmd(TIM2, ENABLE); //TIM2 enable counter
}
void RCC_Configuration(void)+ s; y' |' {5 S, g$ `
{
5 X A4 z9 ^; }- h3 c8 X8 X
RCC_DeInit();
RCC_HSICmd(ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC7 g" \/ K. d; ~9 a3 t. ?
| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE); / [5 I% |( w3 E: k' p$ Z* ]5 M
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //在开启时钟里一定要打开TIM2的时钟
}
RE:STM32步进电机程序
RE:STM32步进电机程序
回复:STM32步进电机程序
RE:STM32步进电机程序
xiexiela