主程序
/******************** (C) COPYRIGHT 2012 Çà·çμç×ó ********************
* ÎļtÃû £omain
* Ãèêö £o
* êμÑéƽ쨣oÇà·çstm32f051¿a·¢°å
* Ãèêö £o°′¼üÖD¶Ï
* ×÷Õß £oÇà·ç
* μêÆì £oqfv5.taobao.com
**********************************************************************/
#include "stm32f0xx.h"
#include "led.h"
#include "exit.h"
#include "uart.h"
unsigned int keyflag=0;
unsigned int downswitchflag=0;
unsigned int upwaterflag=0;
unsigned int RXD_OK_flag=0;
unsigned int AnswerData[7];
int main(void)
{
SystemInit();
LED_Init();
LED_Init1();
USART_Configuration();
AnswerData[1]=0XED; //**μ±Ç°½úμãoÅ****//
AnswerData[2]=0X27; //**é趨½Ç¶èÖμ****//
AnswerData[3]=0X10; //**é趨½Ç¶èÖμ****//
AnswerData[4]=0XEA; //**é趨½Ç¶èÖμ****//
//EXIT_KEY_Init();
while(1)
{
if(RXD_OK_flag==1)
{
USART_SendData(USART1,AnswerData[1]);
USART_SendData(USART1,AnswerData[2]);
USART_SendData(USART1,AnswerData[3]);
USART_SendData(USART1,AnswerData[4]);
RXD_OK_flag=0;
GPIO_ResetBits(GPIOA, GPIO_Pin_3);
GPIO_SetBits(GPIOA, GPIO_Pin_4);
}
}
}
串口配置程序
#include "uart.h"
#include <stdio.h>
//½óêÕ×′ì¬
//bit15£¬ ½óêÕíê3é±êÖ¾
//bit14£¬ ½óêÕμ½0x0d
//bit13~0£¬ ½óêÕμ½μÄóDD§×Ö½úêyÄ¿
unsigned int i0=1;
unsigned int tmp;
unsigned int CommandFromPc[7];
unsigned int ADD;
extern unsigned int RXD_OK_flag;
extern unsigned int AnswerData[7];
void USART_Configuration(void)//′®¿ú3õê¼»ˉoˉêy
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);
/*
* USART1_TX -> PA9 , USART1_RX -> PA10
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;//éèÖÃ′®¿ú2¨ìØÂê
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//éèÖÃêy¾Yλ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//éèÖÃí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No;//éèÖÃD§Ñéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//éèÖÃá÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//éèÖÃ1¤×÷Ä£ê½
USART_Init(USART1, &USART_InitStructure); //ÅäÖÃèë½á11ìå
USART_ClearFlag(USART1,USART_FLAG_TC);
USART_ITConfig(USART1,USART_IT_TC,ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART1_IRQHandler(void)
{
//unsigned int m;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
tmp=USART_ReceiveData(USART1);
//USART_SendData(USART1,tmp);
if(tmp==0xED)
{
RXD_OK_flag=1;
}
}
}
原代码在附件中,目前的现象是如果在接收中断里做应答,自发自收,用串口调试器是可以实现的;但是像现在这样,在串口接收中断里做一个标志位,将标志位传递给主函数,主函数查询到标志位再应答就是不行。我也不知道为什么?好奇怪,请高手能不能帮忙看看,代码不长,就十几行,死活找不到原因,初步分析是接收中断的参数变化没有传递到主函数去。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
今天下午郁闷了一下午,好歹也是玩过F103了,没想到被F030给半了!
还是您们厉害,一眼就看出问题所在,小弟在此感激不尽!!!
一周热门 更多>