数据手册上看.STM32F030R8T6 的PA2 PA3端口 是可以使用usart2的.
- GPIO_InitTypeDef GPIO_InitStruct;
- USART_InitTypeDef USART_InitStruct;
- NVIC_InitTypeDef NVIC_InitStructure;
- //ʱÖÓÅäÖÃ
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
- //gpioÅäÖÃ
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
-
- /* Configure USART Tx as alternate function push-pull */
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- /* Configure USART Rx as alternate function push-pull */
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
-
-
-
- //´®¿ÚģʽÅäÖÃ
- USART_InitStruct.USART_BaudRate =115200;
- USART_InitStruct.USART_WordLength = USART_WordLength_8b;
- USART_InitStruct.USART_StopBits = USART_StopBits_1;
- USART_InitStruct.USART_Parity = USART_Parity_No ;
- USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- USART_Init(USART2, &USART_InitStruct);
-
- USART_Cmd(USART2, ENABLE);
- USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
-
- NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- // NVIC_Config(USART2_IRQn);
复制代码发送使用的 USART_SendData(USART2, data); 不是printf;
可以发送也能接受进入中断.但是数据都不对.
我给电脑发送0XAA 接受的是F9 发送0x01 接受的是E0
电脑给芯片发送0xdd 接受的是FB?
何解啊...哪里的问题?
-
-
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)12000000) /*!< Value of the External oscillator in Hz*/
#endif /* HSE_VALUE */
把这个 从8000000改成12000000就ok了
一周热门 更多>