#include "stm32f10x_lib.h"
#define uint8 u8 #define uint16 u16 #define uint32 u32
#include "NVIC_Init.h" #include "Rcc_Init.h" #include "Usart_Init.h" void GPIO_Configuration(void); void delay(u8 time); u8 i; int main(void) { RCC_Configuration(); GPIO_Configuration(); Usart_Init(); while(1) { delay(100); } }
void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA,ENABLE); /* Configure USART1 Tx (PA.09) as alternate function push-pull */ 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); /* Configure USART1 Rx (PA.10) as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); } void delay(u8 time) {
while(time--); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Usart_Init(void) { USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure; /* USART1 configuration -----------------------------------------------
-------*/ /* USART1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled - USART Clock disabled - USART CPOL: Clock is active low - USART CPHA: Data is captured on the middle - USART LastBit: The clock pulse of the last data bit is not
output to the SCLK pin */ 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; /* Configure the USART1 synchronous paramters */ USART_ClockInit(USART1, &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; /* Configure USART1 basic and asynchronous paramters */ USART_Init(USART1, &USART_InitStructure); /* Enable USART1 */ USART_Cmd(USART1, ENABLE); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Nvic_Init(void) { NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif
/* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the EXTI15_10 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Uart1_PutChar(u16 ch) { while (USART_GetITStatus(USART1,USART_IT_TXE)!=RESET); //USART1->DR = (Data & (uint16_t)0x01FF); //while (*s != '\0') USART_SendData(USART1, ch);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void USART1_IRQHandler(void) { if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET) {
Uart1_PutChar(0x34);
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE); } if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) { USART_ITConfig(USART1, USART_IT_TXE, DISABLE); Uart1_PutChar(0x34); } }
他就是不进中断为啥?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|