gesieniec.lukasz

STM32F301 USART problem

Discussion created by gesieniec.lukasz on Feb 21, 2017
Latest reply on Oct 24, 2017 by Jesus Villanueva

I have found the bug.

It have to be:

GPIO_PinAFConfig(USARTrf_GPIO, GPIO_PinSource10, GPIO_AF_7);

not
GPIO_PinAFConfig(USARTrf_GPIO, GPIO_Pin_10, GPIO_AF_7); -- BUG!!!!!!!!!!!

Hello,

 

I have problem with usart3. I cannot transmit and receive, my uC is STM32F301C8T6.

For test only I have connected rx and tx pins (pb10 and pb11). Below is my initialization and handler code code.

I have tried examples from stdperiph and cube with no results.

 

  #define USARTrf                   USART3
  #define USARTrf_GPIO              GPIOB
  #define USARTrf_CLK               RCC_APB1Periph_USART3
  #define USARTrf_GPIO_CLK          RCC_APB2Periph_GPIOB
  #define USARTrf_RxPin             GPIO_Pin_11
  #define USARTrf_TxPin             GPIO_Pin_10
  #define USARTrf_IRQn              USART3_IRQn
  #define USARTrf_IRQHandler        USART3_IRQHandler

 

  USART_InitTypeDef USART_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
    
       
    USART_DeInit(USARTrf);
    
  /* Connect PXx to USARTx_Tx */
  GPIO_PinAFConfig(USARTrf_GPIO, USARTrf_TxPin, GPIO_AF_7);
 
  /* Connect PXx to USARTx_Rx */
  GPIO_PinAFConfig(USARTrf_GPIO, USARTrf_RxPin, GPIO_AF_7);
    
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Pin = USARTrf_TxPin;
  GPIO_Init(USARTrf_GPIO, &GPIO_InitStructure);
 
  GPIO_InitStructure.GPIO_Pin = USARTrf_RxPin;
  GPIO_Init(USARTrf_GPIO, &GPIO_InitStructure);

        /* Enable USARTrf IRQ */
  NVIC_InitStructure.NVIC_IRQChannel = USARTrf_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
 
  RCC_APB1PeriphClockCmd(USARTrf_CLK, ENABLE);
 
  USART_InitStructure.USART_BaudRate = 19200;
  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(USARTrf, &USART_InitStructure);
 
  USART_Cmd(USARTrf,ENABLE);
    
//  USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
  USART_ITConfig(USARTrf, USART_IT_RXNE, ENABLE);

void USARTrf_IRQHandler(void)
{
    static int error_counter = 0;
    
     if(USART_GetITStatus(USARTrf, USART_IT_RXNE) != RESET)
     {
        rfUSARTProcess(USART_ReceiveData(USARTrf));
        
    } else if(USART_GetITStatus(USARTrf, USART_IT_FE) != RESET) {//od if(USART_GetITStatus(USARTy, USART_IT_RXNE) != RESET)
        error_counter++;
    }

  if(USART_GetITStatus(USARTrf, USART_IT_TXE) != RESET)
  {   
    /* Write one byte to the transmit data register */
    USART_SendData(USARTrf, TxBufferRF[TxCounterRF++]);

    if(TxCounterRF == NbrOfDataToTransferRF)
    {
      /* Disable the USARTrf Transmit interrupt */
      USART_ITConfig(USARTrf, USART_IT_TXE, DISABLE);
            mutex = UNLOCK;
    }    
  }

}

Outcomes