cancel
Showing results for 
Search instead for 
Did you mean: 

USART3 - STM32F103VCT6 doesn't work using PC10 (USART3_TX) / PC11(USART3_RX) pins using REMAP

WGand.1
Associate

I'm trying to use USART3 on STM32F103VCT6 on pins PC10 (USART3_TX) /PC11(USART3_RX) using alternative functions (Remap) and I'm not having success.

From the MCU datasheet I can use these pins for communication.

0693W00000JP9elQAD.png

void UART3_GPIO_Config (void)
{
      //Enable Port C clock
      RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
      RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;//Remap ON
 
 
      //Mode to AF and Fast speed
      GPIOC->CRH &= ~GPIO_CRH_CNF10;
      GPIOC->CRH |= GPIO_CRH_CNF10_1;
      GPIOC->CRH &= ~GPIO_CRH_CNF11;
      GPIOC->CRH |= GPIO_CRH_CNF11_0;//Input Floating
 
      //Output max 10Mhz
      GPIOC->CRH &= ~GPIO_CRH_MODE10;
      GPIOC->CRH |= GPIO_CRH_MODE10_0;
      GPIOC->CRH &= ~GPIO_CRH_MODE11;
 
      //Map to PC10, PC11
      //AFIO->MAPR &= ~AFIO_MAPR_USART3_REMAP;
      //AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP;
      AFIO->MAPR |= (0UL << 5);
      AFIO->MAPR |= (0x1 << 4);
}
void UART3_Config (void)
{
      //UART3 clock enable
      RCC->APB1ENR |= RCC_APB1ENR_USART3EN;
 
      //Transmit Enable
      USART3->CR1 |= USART_CR1_TE;
 
      //Receive Enable
      USART3->CR1 |= USART_CR1_RE;
      //Parity - Even
      USART3->CR1 &= ~(USART_CR1_PS);
      //Parity Control Enable
      USART3->CR1 &= ~(USART_CR1_PCE);
      //Word length = 8bit
      USART3->CR1 &= ~(USART_CR1_M);
      //Stop bits = 1
      USART3->CR2 &= ~(USART_CR2_STOP);
      //Disable Hardware flow control (RTS, CTS)
      USART3->CR3 &= ~(USART_CR3_CTSE);
      USART3->CR3 &= ~(USART_CR3_RTSE);
      //Set Baud rate to 115200 (72MHz = 39.0625 -> 39 / 1)
      //BRR = 72MHz/115200/16 = 39.0625
      //Mantissa = 39
      //Fraction = .0625*16 = 1
      USART3->BRR = 0;
      USART3->BRR |= (39UL << 4);
      USART3->BRR |= (1UL << 0);
 
      //USART3->BRR   = 0x1D4C;//set baud 9600
 
      //Clear LINEN and CLKEN in CR2
      USART3->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN);
      //Clear SCEN, HDSEL and IREN in CR3
      USART3->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN);
      //Enable UART
      USART3->CR1 |= USART_CR1_UE;
 
      /*------------------------------------------------------*/
      // UART3 Receive Interrupt Enable.
      USART3->CR1 |= USART_CR1_RXNEIE;
 
      NVIC_EnableIRQ(USART3_IRQn);
      /*------------------------------------------------------*/
}

Can you help me?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Sara BEN HADJ YAHYA
ST Employee

Hello @WGand.1​ ,

Thanks for your feedback,

I advice you to use CubeMX which is a free tool that allows a very easy configuration of STM32 microcontrollers and microprocessors even for beginners, it also generates the corresponding initialization C code.

Please check this tutorial Getting started with STM32CubeMX

Even with CubeMX you can change the default pin assigned to the IP and use alternative function. You can simply hold the CTRL key and right click on the mouse on the pin and it will show you all the possible changes.

0693W00000JPApIQAX.pngFor more details about this subject, please check my answer in this thread STM32CubeMX - Pinout Config - Select Alternative pins

I hope this help !

If your issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly 🙂

Sara.

View solution in original post

2 REPLIES 2
Sara BEN HADJ YAHYA
ST Employee

Hello @WGand.1​ ,

Thanks for your feedback,

I advice you to use CubeMX which is a free tool that allows a very easy configuration of STM32 microcontrollers and microprocessors even for beginners, it also generates the corresponding initialization C code.

Please check this tutorial Getting started with STM32CubeMX

Even with CubeMX you can change the default pin assigned to the IP and use alternative function. You can simply hold the CTRL key and right click on the mouse on the pin and it will show you all the possible changes.

0693W00000JPApIQAX.pngFor more details about this subject, please check my answer in this thread STM32CubeMX - Pinout Config - Select Alternative pins

I hope this help !

If your issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly 🙂

Sara.

> not having success

Specify. What are your expectations and what are the symptoms?

Don't set USART_CR1.TE/RE before setting up other control bits and USART_BRR.

Other than that, read out and check/post all relevant registers content.

JW