OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2886|回复: 6

mini版STM32编一个循迹小车的程序,用TIM4产生4路PWM,GPIOC来读SenSor的状态,编写以后发现一直报错,而且还不知道怎么解决?

[复制链接]

9

主题

21

帖子

0

精华

初级会员

Rank: 2

积分
120
金钱
120
注册时间
2015-9-16
在线时间
15 小时
发表于 2018-12-2 20:01:54 | 显示全部楼层 |阅读模式
2金钱
用mini版做的循迹小车,其中TIM4产生4路PWM,GPIOC作为读取Sensor状态;程序如下:
Sensor.c
#include "sensor.h"
#include "delay.h"

void SenRead_Init(void)
{
        GPIO_InitTypeDef  GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOC,&GPIO_InitStructure);

       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
        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_IPU;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOC,&GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOC,&GPIO_InitStructure);

}

u8 Sen_Scan(u8 mode)
{
        static u8 sen_up=1;
        if(mode) sen_up=1;
        if(sen_up&(Sen1==0||Sen2==0||Sen3==0|Sen4==0))
        {
                delay_ms(10);
                sen_up=0;
                if(Sen1==0)                            return Sen1_State;
                else if(Sen1==0&&Sen2==0)         return Sen2_State;
                else if(Sen2==0)            return Sen3_State;
                else if(Sen2==0&&Sen3==0)   return Sen4_State;
                else if(Sen3==0)            return Sen5_State;
                else if(Sen3==0&&Sen4==0)        return Sen6_State;
                else if(Sen4==0)            return Sen7_State;
         }
        else if(Sen1==1&&Sen2==1&&Sen3==1&&Sen4==1)
                sen_up=1;
        retrun 0;

}
sensor.h

#ifdef  __SENSOR_H
#define __SENSOR_H

#define Sen1 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_0)
#define Sen2 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_1)
#define Sen3 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2)
#define Sen4 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_3)

#define Sen1_State 1
#define Sen2_State 2
#define Sen3_State 3
#define Sen4_State 4
#define Sen5_State 5
#define Sen6_State 6
#define Sen7_State 7

void SenRead_Init(void);
u8 Sen_Scan();
#endif

PWM.c
#include "pwm.h"
#include "sensor.h"

void TIM4_PWM_Init(u16 arr,u16 psc)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
        TIM_OCInitTypeDef   TIM_OCInitStructure;
       
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOB,GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOB,GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOB,GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOB,GPIO_InitStructure);
       
        TIM_TimeBaseStructure.TIM_Period=arr;
        TIM_TimeBaseStructure.TIM_Prescaler=psc;
        TIM_TimeBaseStructure.TIM_ClockDivision=0;
        TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure);
       
        TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;
        TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
        TIM_OC1Init(TIM4,&TIM_OCInitStructure);
       
        TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;
        TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
        TIM_OC2Init(TIM4,&TIM_OCInitStructure);
       
        TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;
        TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
        TIM_OC3Init(TIM4,&TIM_OCInitStructure);
       
        TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;
        TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
        TIM_OC4Init(TIM4,&TIM_OCInitStructure);
       
       
        TIM_OC1PreloadConfig(TIM4,TIM_OCPreload_Enable);
        TIM_OC2PreloadConfig(TIM4,TIM_OCPreload_Enable);
        TIM_OC3PreloadConfig(TIM4,TIM_OCPreload_Enable);
        TIM_OC4PreloadConfig(TIM4,TIM_OCPreload_Enable);
       
        TIM_Cmd(TIM4,ENABLE);

}

PWM.h
#ifndef __PWM_H
#define __PWM_H

#include "sys.h"

void TIM4_PWM_Init(u16 arr,u16 psc);

#endif


报错代码如下:

compiling pwm.c...
..\HARDWARE\PWM\pwm.c(16): error:  #167: argument of type "GPIO_InitTypeDef" is incompatible with parameter of type "GPIO_InitTypeDef *"
..\HARDWARE\PWM\pwm.c(21): error:  #167: argument of type "GPIO_InitTypeDef" is incompatible with parameter of type "GPIO_InitTypeDef *"
..\HARDWARE\PWM\pwm.c(26): error:  #167: argument of type "GPIO_InitTypeDef" is incompatible with parameter of type "GPIO_InitTypeDef *"
..\HARDWARE\PWM\pwm.c(31): error:  #167: argument of type "GPIO_InitTypeDef" is incompatible with parameter of type "GPIO_InitTypeDef *"
compiling sensor.c...
..\HARDWARE\SENSOR\sensor.c(36): error:  #20: identifier "Sen1" is undefined
..\HARDWARE\SENSOR\sensor.c(36): error:  #20: identifier "Sen2" is undefined
..\HARDWARE\SENSOR\sensor.c(36): error:  #20: identifier "Sen3" is undefined
..\HARDWARE\SENSOR\sensor.c(36): error:  #20: identifier "Sen4" is undefined
..\HARDWARE\SENSOR\sensor.c(40): error:  #20: identifier "Sen1_State" is undefined
..\HARDWARE\SENSOR\sensor.c(41): error:  #20: identifier "Sen2_State" is undefined
..\HARDWARE\SENSOR\sensor.c(42): error:  #20: identifier "Sen3_State" is undefined
..\HARDWARE\SENSOR\sensor.c(43): error:  #20: identifier "Sen4_State" is undefined
..\HARDWARE\SENSOR\sensor.c(44): error:  #20: identifier "Sen5_State" is undefined
..\HARDWARE\SENSOR\sensor.c(45): error:  #20: identifier "Sen6_State" is undefined
..\HARDWARE\SENSOR\sensor.c(46): error:  #20: identifier "Sen7_State" is undefined
..\HARDWARE\SENSOR\sensor.c(50): error:  #20: identifier "retrun" is undefined
..\HARDWARE\SENSOR\sensor.c(50): error:  #65: expected a ";"
..\HARDWARE\SENSOR\sensor.c(52): warning:  #940-D: missing return statement at end of non-void function "Sen_Scan"






























最佳答案

查看完整内容[请看2#楼]

#ifdef __SENSOR_H 写错了
路漫漫其修远兮吾将上下为求索!!!!
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

51

主题

2166

帖子

2

精华

论坛元老

Rank: 8Rank: 8

积分
10653
金钱
10653
注册时间
2017-4-14
在线时间
2780 小时
发表于 2018-12-2 20:01:55 | 显示全部楼层
#ifdef  __SENSOR_H   写错了
回复

使用道具 举报

9

主题

21

帖子

0

精华

初级会员

Rank: 2

积分
120
金钱
120
注册时间
2015-9-16
在线时间
15 小时
 楼主| 发表于 2018-12-2 22:57:34 | 显示全部楼层
改过了,还是不行,还是同样的报错!!!!
路漫漫其修远兮吾将上下为求索!!!!
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2018-12-3 02:31:22 | 显示全部楼层
提示很明显,根据提示去找问题即可。
回复

使用道具 举报

9

主题

21

帖子

0

精华

初级会员

Rank: 2

积分
120
金钱
120
注册时间
2015-9-16
在线时间
15 小时
 楼主| 发表于 2018-12-3 09:16:24 | 显示全部楼层
我在找,只是有的还是不懂什么意思
路漫漫其修远兮吾将上下为求索!!!!
回复

使用道具 举报

109

主题

5564

帖子

0

精华

资深版主

Rank: 8Rank: 8

积分
10572
金钱
10572
注册时间
2017-2-18
在线时间
1914 小时
发表于 2018-12-3 22:03:44 | 显示全部楼层
报错还没解决的话发工程上来~~
回复

使用道具 举报

9

主题

21

帖子

0

精华

初级会员

Rank: 2

积分
120
金钱
120
注册时间
2015-9-16
在线时间
15 小时
 楼主| 发表于 2018-12-4 09:37:14 | 显示全部楼层
peng1554 发表于 2018-12-3 22:03
报错还没解决的话发工程上来~~

已经解决了,谢谢!!!
路漫漫其修远兮吾将上下为求索!!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-22 08:14

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表