各位老师:这个程序为什么就是执行不到while里呢?(就是这条GPIO_Write(GPIOD, 0x0700);)单步(F11)的时候可以的,但F10执行职能到NVIC_Configuration(); 到这里就执行不下去了,到不了while里。发送数据4或5都得到现象的(中断是进去了的),为什么while就进不去呢?我刚学,弄了好几天,搞不定,请求各位高手,谢谢了
#include "stm32f10x.h"
#include <stdio.h>
/* Private function prototypes -----------------------------------------------*/
void GPIO_Configuration(void);
void USART_Configuration(void);
void NVIC_Configuration(void);
//void EXTI_Configuration(void);
void Delay (uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
int main(void)
{
GPIO_Configuration();
USART_Configuration();
NVIC_Configuration();
/* Infinite loop */
while (1)
{
GPIO_Write(GPIOD, 0x0700);
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD , ENABLE);
/**
* LED1 -> PD8 , LED2 -> PD9 , LED3 -> PD10 , LED4 -> PD11
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; ;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
void USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1,ENABLE);
/*
* USART1_TX -> PA9 , USART1_RX -> PA10
*/
USART_DeInit(USART1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
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_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
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(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
USART_Cmd(USART1, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/*
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART1_IRQHandler(void)
{
unsigned char i;//temp[250];
if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)!= RESET)
{
USART_ClearITPendingBit(USART1, USART_FLAG_RXNE);
i = USART_ReceiveData(USART1);
if(i==0x35)
{
GPIO_Write(GPIOD, 0x0700);
}
if(i==0x34)
{
GPIO_Write(GPIOD, 0x0E00);
}
USART_SendData(USART1,i);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) ;
}
}
此帖出自
小平头技术问答
这个偶尔也会遇到,不过我倒是一直找不到好的解决办法
一周热门 更多>