头像-155856

a2605

个人成就

获得 5 次赞

帮助过4人

为什么PB7一直无法输出PWM呢?

void BLDC_TIM_Config(void){ GPIO_InitTypeDef  GPIO_InitStructure; TIM_TimebaseInitTypeDef  TIM_TimebaseInitStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ENABLE);   //2、初始化PB7引脚 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;  //引脚7 LED1 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速度 GPIO_Init(GPIOB&GPIO_InitStructure); TIM_TimebaseInitStructure.TIM_Prescaler     = VREF_TIM_PSC; TIM_TimebaseInitStructure.TIM_Period        = VREF_TIM_PERIOD; TIM_TimebaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimebaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimebaseInit(TIM4&TIM_TimebaseInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OC2Init(TIM4&TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM4TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM4ENABLE); TIM_Cmd(TIM4ENABLE);}这些是定义//VREF   输出比较通道-PB7#define VREF_TIM_CH2_GPIO_CLK  RCC_APB2Periph_GPIOB#define VREF_TIM_CH2_PIN GPIO_Pin_7#define VREF_TIM_CH2_PORT GPIOB//VREF-BKIN  输出比较通道的刹车通道//#define VREF_TIM_BKIN_CLK  RCC_APB2Periph_GPIOB//#define VREF_TIM_BKIN_PIN GPIO_Pin_7//#define VREF_TIM_BKIN_PORT GPIOB//定时器配置#define            VREF_TIM_APBxClock_FUN     RCC_APB1PeriphClockCmd#define            VREF_TIM_CLK               RCC_APB1Periph_TIM4#define            VREF_TIM                   TIM4//PWM 信号的频率 F = TIM_CLK/{(ARR+1)*(PSC+1)}#define VREF_TIM_PERIOD        719                    #define VREF_TIM_PSC       9                       #define VREF_TIM_PULSE         360                   ​这些是对应的定义,int main(void) { BLDC_TIM_Config(); while(1)    {    GPIO_SetBits(GPIOB GPIO_Pin_7); } }​主程序没啥问题啊,就是做个测试,一直无法输出PWM

L6235PD,引脚定义怎么控制

Vref---,Diag---, EN---高电平使能,低电平无效,Fwd/Rev---高电平正转,低电平倒转,Brake---, Tacho---, H1---读取霍尔1 H2---读取霍尔2 H3---读取霍尔3, 上面是我看出来得东西,有几个确实没看懂,大家帮忙看下是什么定义,怎么控制呢?使用得芯片是L6235PD,

L6235pd怎么驱动电机

最近想玩一下一直吃灰得板子,板子是之前从别人机器上拆下来得,电路图已经摸了一遍,基本摸清楚了。目前我想用这款板子上的单片机和L6235这两个片子去驱动我的电机。但我这几天查资料后,已经没有太多得资料,这种老片子了现在想请教一下各位大佬,1,关于电机驱动得代码实现思路2,如果有L6235得资料或者相关例程,能否发小弟一份,万分感激3,代码实现注意事项或者一些好的建议

ATxmega64A3uAU。头文件源码包

之前一直在用ST得片子,最近手头有两个吃灰得AT片子想用一下,发现已然没了啥资料。各位大佬有的话,麻烦发我一下,另外得话,各位大佬有好用得编译器分享一下吗,类似于KEIL,这种。

AVR下载烧录。在线等

大佬们,Atxmega64A3U我用的片子,最近刚准备学AVR,xmega除了可以用PDI,还可以用别的方式吗,请教下大佬,帮忙普及解释下我目前不理解的几个问题:1,AVR有常见的两种烧录方式,ISP和PDI,这两种有什么区别呢,为啥还分了两种呢,度娘说法太绕了,简单直白说明一下就好2,Atxmega64A3U这个片子可以用ISP下载吗3,xmega度娘上很多说可以用串口烧录,有会的大佬说明一下吗?另外建议这样操作吗?4,目前手头有个ISP的AVR下载器,不知能否改成带PDI下载的,网上看到有人改成功过,​在线等!在线等!在线等!​​​

铅酸电池,在充电状态下和放置状态下的挥发气味

1,铅酸蓄电池在放置的情况下,未接任何元器件,铅酸蓄电池是否会通过排气孔挥发气味2,铅酸电池在放电或充电的情况下,会挥发气味,其气味包含哪些成分3,铅酸电池散发气味是否对人体有害4,如果有害,应该如何避免操作,用防水透气膜封住通气孔是否可以

刚刚开始学习单片机,串口收数据量稍微大点,程序卡死

代码已粘贴,请各位大佬帮忙分析下是什么原因造成得。万分感谢sys_config.c #include "sys_config.h" #include "stm32f10x.h" #include "stm32f10x_adc.h" #include "stm32f10x_bkp.h" #include "stm32f10x_can.h" #include "stm32f10x_cec.h" #include "stm32f10x_crc.h" #include "stm32f10x_dac.h" #include "stm32f10x_dbgmcu.h" #include "stm32f10x_dma.h" #include "stm32f10x_exti.h" #include "stm32f10x_flash.h" #include "stm32f10x_fsmc.h" #include "stm32f10x_gpio.h" #include "stm32f10x_i2c.h" #include "stm32f10x_iwdg.h" #include "stm32f10x_pwr.h" #include "stm32f10x_rcc.h" #include "stm32f10x_rtc.h" #include "stm32f10x_sdio.h" #include "stm32f10x_spi.h" #include "stm32f10x_tim.h" #include "stm32f10x_usart.h" #include "stm32f10x_wwdg.h" #include "misc.h" /@@*USART1配置*/ void USART1_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ENABLE ); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART1 TX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA &GPIO_InitStructure); //端口A; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //USART1 RX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA &GPIO_InitStructure); //端口A; USART_InitStructure.USART_BaudRate = 115200; //波特率; USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据位8位; USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位1位; USART_InitStructure.USART_Parity = USART_Parity_No ; //无校验位; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件流控; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//收发模式; USART_Init(USART1 &USART_InitStructure);//配置串口参数; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置中断组,4位抢占优先级,4位响应优先级; NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //中断号; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //抢占优先级; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //响应优先级; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(USART1 USART_IT_RXNE ENABLE); USART_Cmd(USART1 ENABLE); //使能串口; } /@@*发送一个字节*/ void USART1_Send_Byte(u8 Data) //发送一个字节; { USART_SendData(USART1Data); while( USART_GetFlagStatus(USART1 USART_FLAG_TC) == RESET ); } void USART1_Send_String(u8 *Data) //发送字符串; { while(*Data) USART1_Send_Byte(*Data++); } void USART1_IRQHandler(void) //中断处理函数; { u8 res; if(USART_GetITStatus(USART1 USART_IT_RXNE) == SET) //判断是否发生中断; { USART_ClearFlag(USART1 USART_IT_RXNE); //清除标志位; res=USART_ReceiveData(USART1); //接收数据; USART1_Send_Byte(res); //用户自定义; } } /@@*USART2配置*/ void USART2_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART2 &USART_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(USART2 USART_IT_RXNE ENABLE); USART_Cmd(USART2 ENABLE); } void USART2_Send_Byte(u8 Data) //发送一个字节; { USART_SendData(USART2Data); while( USART_GetFlagStatus(USART2 USART_FLAG_TC) == RESET ); } void USART2_Send_String(u8 *Data) //发送字符串; { while(*Data) USART2_Send_Byte(*Data++); } void USART2_IRQHandler(void) //中断处理函数; { u8 res; if(USART_GetITStatus(USART2 USART_IT_RXNE) == SET) //判断是否发生中断; { USART_ClearFlag(USART2 USART_IT_RXNE); //清除标志位; USART_ClearITPendingBit(USART2 USART_IT_RXNE); res=USART_ReceiveData(USART2); //接收数据; USART2_Send_Byte(res); //用户自定义; } } void UART4_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4 ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(UART4 &USART_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(UART4 USART_IT_RXNE ENABLE); USART_Cmd(UART4 ENABLE); } void UART4_Send_Byte(u8 Data) { USART_SendData(UART4Data); while( USART_GetFlagStatus(UART4 USART_FLAG_TC) == RESET ); } void UART4_Send_String(u8 *Data) { while(*Data) UART4_Send_Byte(*Data++); } void UART4_IRQHandler(void) { u8 res; if(USART_GetITStatus(UART4 USART_IT_RXNE) == SET) { USART_ClearFlag(UART4 USART_IT_RXNE); res=USART_ReceiveData(UART4); UART4_Send_Byte(res); } } void UART5_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5 ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(UART5 &USART_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(UART5 USART_IT_RXNE ENABLE); USART_Cmd(UART5 ENABLE); } void UART5_Send_Byte(u8 Data) { USART_SendData(UART5Data); while( USART_GetFlagStatus(UART5 USART_FLAG_TC) == RESET ); } void UART5_Send_String(u8 *Data) { while(*Data) UART5_Send_Byte(*Data++); } void UART5_IRQHandler(void) { u8 res; if(USART_GetITStatus(UART5 USART_IT_RXNE) == SET) { USART_ClearFlag(UART5 USART_IT_RXNE); res=USART_ReceiveData(UART5); UART5_Send_Byte(res); } } /@@*......GPIO配置......*/ void GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; //定义初始化结构体 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ENABLE); GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable ENABLE);////关闭jtag功能 //SYS-LED GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA &GPIO_InitStructure); } /@@*重新定义USART1-printf配置*/ int fputc(int ch FILE *f) { while(USART_GetFlagStatus(USART1USART_FLAG_TC)==RESET); USART_SendData(USART1(uint8_t)ch); return ch; } /@@*重新定义scanf到串口,用于scanf,getchar等*/ int fgetc(FILE *f) { /@@*等待串口输入数据*/ while (USART_GetFlagStatus(USART1 USART_FLAG_RXNE) == RESET); return (int)USART_ReceiveData(USART1); } /@@*独立看门狗*/ void IWDG_Feed(void) { IWDG_ReloadCounter(); } //#if 0 //void EXTI_Config(void) //{ // EXTI_InitTypeDef EXTI_InitStructure; // /@@*PD11外部中断输入*/ // EXTI_InitStructure.EXTI_Line = EXTI_Line13; // EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; // EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; // EXTI_InitStructure.EXTI_LineCmd = ENABLE; // EXTI_Init(&EXTI_InitStructure); // // /@@*PD12外部中断输入*/ // EXTI_InitStructure.EXTI_Line = EXTI_Line12; // EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; // EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; // EXTI_InitStructure.EXTI_LineCmd = ENABLE; // EXTI_Init(&EXTI_InitStructure); //} //#endif sys_config.h #ifndef __SYS_CONFIG_H_ #define __SYS_CONFIG_H_ #include "stm32f10x_conf.h" #include "stm32f10x.h" #include <stdio.h> /@@*使用位带操作,对单个IO灵活操作*/ #define GPIOA_ODR_Addr (GPIOA_base+12) //0x4001080C #define GPIOB_ODR_Addr (GPIOB_base+12) //0x40010C0C #define GPIOC_ODR_Addr (GPIOC_base+12) //0x4001100C #define GPIOD_ODR_Addr (GPIOD_base+12) //0x4001140C #define GPIOE_ODR_Addr (GPIOE_base+12) //0x4001180C #define GPIOF_ODR_Addr (GPIOF_base+12) //0x40011A0C #define GPIOG_ODR_Addr (GPIOG_base+12) //0x40011E0C #define GPIOA_IDR_Addr (GPIOA_base+8) //0x40010808 #define GPIOB_IDR_Addr (GPIOB_base+8) //0x40010C08 #define GPIOC_IDR_Addr (GPIOC_base+8) //0x40011008 #define GPIOD_IDR_Addr (GPIOD_base+8) //0x40011408 #define GPIOE_IDR_Addr (GPIOE_base+8) //0x40011808 #define GPIOF_IDR_Addr (GPIOF_base+8) //0x40011A08 #define GPIOG_IDR_Addr (GPIOG_base+8) //0x40011E08 #define PFout(n) *((volatile unsigned long *)(0x42000000+((GPIOF_ODR_Addr-0x40000000)<<5)+(n<<2))) void GPIO_Config(void); void EXTI_Config(void); void IWDG_Feed(void); void USART1_Configuration(void); void USART2_Configuration(void); void UART4_Configuration(void); void UART5_Configuration(void); void USART1_IRQHandler(void); void USART2_IRQHandler(void); void UART4_IRQHandler(void); void UART5_IRQHandler(void); #endif main.c #include <stdio.h> #include "stm32f10x.h" #include "sys_config.h" #include "sys_led.h" #include "delay.h" #include "sys_relay.h" #include "stm32f10x_iwdg.h" /@@*SYS_LED*/ int main(void) { uint8_t temp1; USART1_Configuration(); USART2_Configuration(); UART4_Configuration(); UART5_Configuration(); LED_GPIO_Config(); GPIO_Config(); OUT_GPIO_Config(); IWDG_Feed(); printf("\r\n start tset.......................\r\n"); while(1) { LED_ON; delay_ms(2500); LED_OFF; delay_ms(2500); USART_SendData(USART1'1'); printf("\r\n uart1 send:%c\r\n"); USART_SendData(USART2'2'); printf("\r\n uart2 send:%c\r\n"); USART_SendData(UART4'4'); printf("\r\n uart4 send:%c\r\n"); USART_SendData(UART5'5'); printf("\r\n uart5 send:%c\r\n"); printf("\r\n send ok.......................\r\n"); temp1 = USART_ReceiveData(USART1); printf("\r\n received %c\r\n" temp1); if(temp1 == '1'){ printf("\r\n OUT1_ON.......................\r\n"); OUT1_ON; } else if(temp1 == '2'){ printf("\r\n OUT1_OFF.......................\r\n"); OUT1_OFF; } else if(temp1 == '3'){ printf("\r\n OUT2_ON.......................\r\n"); OUT2_ON; } else if(temp1 == '4'){ printf("\r\n OUT2_OFF.......................\r\n"); OUT2_OFF; } else if(temp1 == '5'){ printf("\r\n OUT3_ON.......................\r\n"); OUT3_ON; } else if(temp1 == '6'){ printf("\r\n OUT3_OFF.......................\r\n"); OUT3_OFF; } else if(temp1 == '7'){ printf("\r\n OUT4_ON.......................\r\n"); OUT4_ON; } else if(temp1 == '8'){ printf("\r\n OUT4_OFF.......................\r\n"); OUT4_OFF; } } }

STM32 debug

如题,STM32单片机中,例F103单片机,串口有3-5个不等,可以将串口1-5所有的收发内容,集中debug到串口1日志上吗?可以的话,方便告知下思路?