学前班
最后登录1970-1-1
在线时间 小时
注册时间2015-7-13
|
我用的是老版本的M3,目测有些年头了。最近在用这块板子做串口通信试验,可以从板子上发送数据到PC上,但是无法从PC上发送数据到单片机。检查了好几遍串口中断程序,没发现什么问题。那么怎么检查是不是硬件问题?
老版本M3
以下是串口中断配置相关的代码:
- void USART1_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
-
- /* config USART1 clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
-
- /* USART1 GPIO config */
- /* 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);
-
- /* USART1 mode config */
- 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);
-
- //使能串口1 接收终中断
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
-
- USART_Cmd(USART1, ENABLE);
- }
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- /* Configure the NVIC Preemption Priority Bits */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
-
- /* Enable the USARTy Interrupt */
- 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)
- {
- u8 c;
- printf("这是来自串口的中断");
- if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
- {
- c=USART1->DR;
- printf("%c",c); //将接受到的数据直接返回打印
- }
-
- }
复制代码 经测试,无法进入串口中断函数。向M3发送数据没有反应。
|
|