我初学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 ) ; } |
STM32F107+LWIP---如何检查tcp通讯断开?并重新连接
有没有用过数字式mems麦克风的,想问下SPI通讯的问题
stm32f103 CAN通讯多帧发送问题?
STM32F107作为USB主机模拟串口通讯不成功(采用PL2303芯片)
STM32F103C8 LIN通讯例程
求助,丐版J-Link通讯不上
ethernet可以与ethercat通讯吗?
LIS3DH SPI 通讯问题
STM32F373 CAN通讯问题CAN_FLAG_LEC
请教高手看看,STM32F1的多机通讯,地址匹配唤醒问题
RE:有关stm32f107VC USART通讯求助
这个用的是串口0吧