各位大大好 小弟我最近用STM32F042K6T7
其上面的USART1和USART2各有两组
USART1:
1 2
TX: PA9 PB6
RX: PA10 PB7
USART2:
1 2
TX: PA2 PA14
RX: PA3 PA15
我使用USART1的第2組
但是程序执行到
USART_Init(USART1, &USART_InitStructure);
这一行时我的register CR1 內的RE和TE
都没有启动,而且进入library程序内看发现有执行这一行
USARTx->CR1 = tmpreg;
tmpreg內是有值的,但是怎么执行USARTx->CR1一直等于0,一直写不进去
这问题已经2.3天一直无法解决,所以来这里求助
盼有没有高手大大指点一下迷津,程序如下
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Enable USART clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* Connect PXx to USARTx_Tx and USARTx_Rx */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0);
//--**--// AF - Tx
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//--**--// AF - Rx
/* Configure USART Rx as alternate function push-pull */
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
//GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;//115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;//USART_Parity_Odd;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
//USART_Configuration(&USART_InitStructure);
/* USART configuration */
USART_Init(USART1, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART1, ENABLE);
|