2012-12-06 09:46 PM
Hi,
I am trying to communicate to STM32F107VC microcontroller via UART5. I am debugging the DR register of UART5 port, but it seems it is always zero (I am using IAR EWARM with ST-LINK V2 via STM32F1Discovery). the PCLK1 is configured to be 31.25 MHz Here is my code: main.c: --------/* Setup STM32 system (clock, PLL and Flash configuration) */
RCC_init(); IO_init(); USART_init(); //EXT_CRT_SECTION(); // send test data to USART1/* Infinite loop */
while (1) { // send test data via USART1 USART_SendData(UART5, (uint16_t)'T'); while(USART_GetFlagStatus(UART5,USART_FLAG_TXE) == RESET); // wait until the TDR (Tx register) data is transfered to the shift register LED_Test(); } } -------------------------------------------------------------------------------------------- init.c: ----- void USART_init(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART1_InitStructure; USART_InitTypeDef UART5_InitStructure; // Release reset and enable clock USART_DeInit(UART5); RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD,DISABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC,DISABLE); /* UART5 Configuration *=====================*/ // configure the IO ports for UART5 Tx as output GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); // configure the IO ports for UART5 Rx as input GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD, &GPIO_InitStructure); // configure the UART5 serial registers UART5_InitStructure.USART_BaudRate = 115200; UART5_InitStructure.USART_WordLength = USART_WordLength_8b; UART5_InitStructure.USART_StopBits = USART_StopBits_1; UART5_InitStructure.USART_Parity = USART_Parity_No; UART5_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; UART5_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_Init(UART5,&UART5_InitStructure); // enable UART5 USART_Cmd(UART5, ENABLE); } stm32f10x_usart.c ------------------ void USART_SendData(USART_TypeDef* USARTx, uint16_t Data) { /* Check the parameters */ assert_param(IS_USART_ALL_PERIPH(USARTx)); assert_param(IS_USART_DATA(Data)); /* Transmit Data */ USARTx->DR = (Data & (uint16_t)0x01FF); }2012-12-07 04:44 AM
So, DR means different things depending if your reading or writing. When reading your are seeing the RECEIVED data, which would come from the PC or other external source.