你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 1985|回复: 1

有关stm32f107VC USART通讯求助

[复制链接]

1

主题

3

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2012-10-9 12:11:01 | 显示全部楼层 |阅读模式
 我初学STM32F107的板子,做了USART的实验,就是通过按键中断向PC终端发送程序。程序做完后,用keil编译没什么问题,但是数据总是发不了?程序就在下边,麻烦各位大神看看。。
 
#include "stm32f10x_lib.h"
#include "stm32f10x.h"
#include
EXTI_InitTypeDef EXTI_InitStructure;
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void USART_Configuration(void);
 
int main (void)
{
RCC_Configuration();
GPIO_Configuration();
NVIC_Configuration();
USART_Configuration();
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource7);
EXTI_InitStructure.EXTI_Line = EXTI_Line7;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_GenerateSWInterrupt(EXTI_Line7);
printf("System: nothing is impossible!\n");
        while(1)
        {
        }
}
 
void RCC_Configuration(void)
{
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOD, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
 
}
 
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD,&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOD,&GPIO_InitStructure);
}
 
void NVIC_Configuration(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
          NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
         NVIC_Init(&NVIC_InitStructure);
}
 
void USART_Configuration(void)
{
  USART_InitTypeDef USART_InitStructure;
  USART_ClockInitTypeDef USART_ClockInitStructure;
  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);
  USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;          
  USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
  USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
  USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
  USART_ClockInit(USART2,&USART_ClockInitStructure);
  USART_Cmd(USART2, ENABLE);
}
 
 
int fput(int ch, FILE * f)
 {
 USART_SendData(USART2,(u8)ch);
 while(USART_GetFlagStatus(USART2,USART_FLAG_TC) == RESET)
 {
 }         
        return ch;
 }
 
 这下变的是中断程序
#include "stm32f10x_it.h"
#include
 
void EXTI9_5_IRQHandler(void)
{
 if (EXTI_GetITStatus(EXTI_Line7) != RESET) 
 printf ( "\n the 7th external interrupt happend!\n");
 EXTI_ClearITPendingBit( EXTI_Line7 ) ;
}

 
 
<
回复

使用道具 举报

134

主题

4489

回帖

239

蝴蝶豆

版主

最后登录
2020-12-9
发表于 2012-10-9 16:30:39 | 显示全部楼层

RE:有关stm32f107VC USART通讯求助

printf ( &quot;\n the 7th external interrupt happend!\n&quot;);
这个用的是串口0吧
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版