你的浏览器版本过低,可能导致网站不能正常访问!为了你能正常使用网站功能,请使用这些浏览器。
意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的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;" V U0 N. F, O" n9 P$ O
ErrorStatus HSIStartUpStatus;7 H% N9 n# s; A' d! f% p
void NVIC_Configuration(void);" N* K2 I& k6 L5 [
void RCC_Configuration(void);
void TIM2_Configuration(void);9 _3 j. M, I! ]4 r
void GPIO_Configuration(void);
#define VECT_TAB_RAM, y2 J+ u9 b9 Z" X
int main(void)2 Y% l: {: [; O! c
{
#ifdef DEBUG
debug();/*[初始化外围设备指针]*/1 ` s6 d: Z0 k
#endif
RCC_Configuration(); //初始化时钟与复位 3 O/ I; s/ k! I$ a
NVIC_Configuration();//初始化中断嵌套
TIM2_Configuration();//初始化定时器1 O4 O- l7 b8 z. o* R- g
GPIO_Configuration();
GPIO_WriteBit(GPIOD, GPIO_Pin_7, (BitAction)(0));7 }# @1 {. b5 s$ t: u, [2 O7 N) J
GPIO_WriteBit(GPIOD, GPIO_Pin_6, (BitAction)(0)); //DCY1 DCY2为00,即Normal %0 DECAY8 a6 t/ c: z. C; O) |! e1 T' z
GPIO_WriteBit(GPIOE, GPIO_Pin_7, (BitAction)(1));
GPIO_WriteBit(GPIOB, GPIO_Pin_1, (BitAction)(0)); //M1M2为10,即1-2-phase
GPIO_WriteBit(GPIOA, GPIO_Pin_4, (BitAction)(0)); //正向旋转
GPIO_WriteBit(GPIOB, GPIO_Pin_0, (BitAction)(0));/ a! ?5 M% }5 M! Y# z( B; Q' I- k
GPIO_WriteBit(GPIOC, GPIO_Pin_5, (BitAction)(1)); //TQ1 TQ2为01,即Current Ratio为50%
GPIO_WriteBit(GPIOA, GPIO_Pin_7, (BitAction)(1)); //StepReset位
GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(1)); //StepEn 使能位5 g$ ?% m4 L) V& b9 @+ f6 v
while(1)+ d9 ]( i; z3 ]2 {4 X; z% i
{1 K1 G+ ~; w1 N+ w1 x! X
}! e% J8 Z) i) l% X0 t( d
}
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,StepReset* e9 p g: h" T! P7 T" u
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;0 w; y, f" {4 K0 T1 l* b
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);( @4 ^. r, |% B V: a
GPIO_InitStructure.GPIO_Pin= GPIO_Pin_5 | GPIO_Pin_6; //PA的6.7接Protect和Mo 6 ]; V$ C6 ]! [7 {" R( L4 F: [
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;, H. X3 o$ e) _2 i3 H8 a$ j
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;, R9 U! w/ O+ H4 _% G
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4 | GPIO_Pin_5; //PC的4.5接StepEn和TQ2 ! Y0 T/ U. [* Z: h9 p6 A( v
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;: a/ x6 H- ^2 x: s6 I! `
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1; //PB的0.1接TQ1和M22 x) k& n. l1 [' R: n2 M* i: R
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;/ i+ c z5 N# T% h
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7; //PE7接M1 ! ?0 m( t' S. G) f* s
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;8 c2 u3 [! k+ l" J3 N7 X
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStructure);' D* O6 S G& x
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;' }2 M* t) V+ a, E- h
GPIO_Init(GPIOD,&GPIO_InitStructure);, H$ Y& k# ^" r& ?. f
} v0 K! t( x* g% Y
void NVIC_Configuration(void)
{5 F5 O2 E9 S* \, [3 l) m
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM ) `) b5 D2 X4 Z
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else ; t/ ?4 U! q) d7 s( E( n5 e
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
4 h( u/ c% N4 N W4 N
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //设置TIM2通道输入中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /*配置优先级组*/, x' l0 F0 b7 L1 U1 ~, y9 l
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 2 e9 F" \; ]3 q; n1 `- W7 O# A
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /*允许TIM2全局中断*/8 q3 D- c' k) B2 F3 P$ _
NVIC_Init(&NVIC_InitStructure);
}7 ^1 D( V' x9 F' d9 v; K
void TIM2_Configuration(void)7 q* ?( A4 J+ j# O9 Q3 ]
{
TIM_SetCounter( TIM2, 0x0000);7 d& M' M N! m9 s* @1 K9 J4 X
TIM_ClearFlag(TIM2, TIM_FLAG_Update); /*清除更新标志位*/
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); //清除TIM2等待中断更新中断标志位
TIM_ARRPreloadConfig(TIM2, ENABLE); /*预装载寄存器的内容被立即传送到影子寄存器 */
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); //使能TIM2的更新 % ?5 Y( J+ X! ^& b$ e3 D( @: d
$ E+ d/ y. E% `+ ]* b
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 120; //设定的最大计数值,计数值到则产生一次中断
TIM_TimeBaseStructure.TIM_Prescaler = 30; //分频
TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 时钟分割5 h# n8 N3 ?) f$ p9 d6 R7 @ u
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //计数方向向上计数# |3 H4 t8 M2 b/ v* M& r
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_Cmd(TIM2, ENABLE); //TIM2 enable counter
}
void RCC_Configuration(void)# G: i8 j6 P" D( z2 y8 r% |
{7 }# b" ?- J& X' S: b& @
; n8 j$ j' Y/ R( x7 t
RCC_DeInit();
RCC_HSICmd(ENABLE);1 U. ^. Z7 D+ v9 D C
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC! D" {2 w8 c+ E6 L$ J
| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE); % K7 y* V t- [/ n6 x
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //在开启时钟里一定要打开TIM2的时钟
}
RE:STM32步进电机程序
RE:STM32步进电机程序
回复:STM32步进电机程序
RE:STM32步进电机程序
xiexiela