你的浏览器版本过低,可能导致网站不能正常访问!为了你能正常使用网站功能,请使用这些浏览器。
意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的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;3 u% F& O% |" _- |1 B( V
ErrorStatus HSIStartUpStatus;
void NVIC_Configuration(void);
void RCC_Configuration(void);
void TIM2_Configuration(void);
void GPIO_Configuration(void);, ^1 |4 H. D/ c* F0 k
#define VECT_TAB_RAM1 t+ n0 Z0 k. W9 N6 [
int main(void)7 v4 a' v1 B1 }# |
{
#ifdef DEBUG% R" g# Y9 g1 b5 P7 h7 r
debug();/*[初始化外围设备指针]*/+ x7 m0 n3 J( ?
#endif4 w# t2 T% z$ V8 ~, _# _4 K+ g' J7 A: R8 a
RCC_Configuration(); //初始化时钟与复位
NVIC_Configuration();//初始化中断嵌套
TIM2_Configuration();//初始化定时器 L1 Q5 q" `$ z' w* m" E
GPIO_Configuration();
; r2 N2 f; T# s! S! [- [! S
GPIO_WriteBit(GPIOD, GPIO_Pin_7, (BitAction)(0));
GPIO_WriteBit(GPIOD, GPIO_Pin_6, (BitAction)(0)); //DCY1 DCY2为00,即Normal %0 DECAY
GPIO_WriteBit(GPIOE, GPIO_Pin_7, (BitAction)(1));
GPIO_WriteBit(GPIOB, GPIO_Pin_1, (BitAction)(0)); //M1M2为10,即1-2-phase' U5 q+ `$ u( |0 B
, A4 x# B% u4 b( e* V" J8 k
GPIO_WriteBit(GPIOA, GPIO_Pin_4, (BitAction)(0)); //正向旋转6 @) m- ]# Q$ B2 f- J
GPIO_WriteBit(GPIOB, GPIO_Pin_0, (BitAction)(0));
GPIO_WriteBit(GPIOC, GPIO_Pin_5, (BitAction)(1)); //TQ1 TQ2为01,即Current Ratio为50%+ a! i2 h. q/ B5 _( |9 M
GPIO_WriteBit(GPIOA, GPIO_Pin_7, (BitAction)(1)); //StepReset位
GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(1)); //StepEn 使能位
while(1) n0 @, k: y1 {. t
{8 h8 ~3 c$ Y' W+ ^% U/ n# o
}% ]4 U5 C7 E }
}
void GPIO_Configuration(void) : ]8 C7 \$ w3 a( o& }
{ 5 @/ u6 B4 u' H5 X( v4 E
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
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);$ Q: \- x1 Q6 ?& B" c: K# i
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);0 s% X c; `; w& I& T1 x
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4 | GPIO_Pin_5; //PC的4.5接StepEn和TQ2
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;) t" P( e/ {! T
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
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;) m* e& w Y! ?" ?* ?# Q# `
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7; //PE7接M1
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;$ f1 W, ]0 l- S
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStructure);/ a5 r# y/ e( ]
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6 | GPIO_Pin_7; //PD的67接DCY2和DCY1# w$ U* n9 W U, p* }4 f
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;+ i. T% K: ~% |5 j9 q+ H
GPIO_Init(GPIOD,&GPIO_InitStructure);# C0 _' [5 U1 e% s* H
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
4 h% g; F- s5 u {6 }+ L7 ^
#ifdef VECT_TAB_RAM ( m* O2 |9 ?( l
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else 3 F) x; n) I6 k& p
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); 3 x. {0 N T! B5 M1 K0 d
#endif
# b. x/ ~6 ?& X; v8 E
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //设置TIM2通道输入中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /*配置优先级组*/
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 8 ]0 e4 B+ F! w: i1 {
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /*允许TIM2全局中断*/$ O* g7 M; a: a$ o
NVIC_Init(&NVIC_InitStructure);
}4 y9 } \" E: M5 Y% t2 l
void TIM2_Configuration(void)
{
TIM_SetCounter( TIM2, 0x0000);' A8 F' q- O* @: m
TIM_ClearFlag(TIM2, TIM_FLAG_Update); /*清除更新标志位*/
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); //清除TIM2等待中断更新中断标志位
TIM_ARRPreloadConfig(TIM2, ENABLE); /*预装载寄存器的内容被立即传送到影子寄存器 */ * c, X, u" P! I/ D6 N+ r9 l
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); //使能TIM2的更新
0 j& I4 L( Z/ |) M% I* n2 k4 i
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);
TIM_Cmd(TIM2, ENABLE); //TIM2 enable counter1 M# q) R6 @4 M/ p# J' |0 m
}
void RCC_Configuration(void), t3 y0 J- v( Q* L4 j
{
2 F/ o- i$ K1 Y* x3 N: Y/ B
RCC_DeInit();
RCC_HSICmd(ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //在开启时钟里一定要打开TIM2的时钟
}
RE:STM32步进电机程序
RE:STM32步进电机程序
回复:STM32步进电机程序
RE:STM32步进电机程序
xiexiela