AnsweredAssumed Answered

MB1034B STM32F0DISCOVERY problem on UART1 PA10

Question asked by Bandini.Matteo on Sep 7, 2012
Latest reply on Sep 7, 2012 by Bandini.Matteo
I'm using 

STM32F0DISCOVERY


I can't receive any char on UART, no interrrupt!

Here my initialization:


#define RCC_PORT_RX                     RCC_AHBPeriph_GPIOA
#define GPIO_PORT_RX                     GPIOA
#define GPIO_PIN_RX                         GPIO_Pin_10
#define GPIO_PIN_SOURCE_RX               GPIO_PinSource10
#define GPIO_AF_RX_PIN                     GPIO_AF_1
#define RCC_PORT_UART                     RCC_APB2Periph_USART1
#define USART_X                               USART1


#define RCC_PORT_DEBUG                RCC_AHBPeriph_GPIOC
#define GPIO_PORT_DEBUG           GPIOC
#define GPIO_PIN_DEBUG                GPIO_Pin_8

#define DEBUG_ON()   GPIO_SetBits  ( GPIO_PORT_DEBUG, GPIO_PIN_DEBUG )
#define DEBUG_OFF()  GPIO_ResetBits  ( GPIO_PORT_DEBUG, GPIO_PIN_DEBUG )

unsigned char UART_Init(UART_BPS bps) {


  NVIC_InitTypeDef NVIC_InitStructure;
     GPIO_InitTypeDef GPIO_InitStructure;


  /* Enable the USART1 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
     
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_Odd;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx;
     USART_InitStructure.USART_BaudRate = bps;
     
     /* Enable GPIO clock */
   RCC_AHBPeriphClockCmd(RCC_PORT_RX, ENABLE);
     /* Enable USART clock */
     RCC_APB2PeriphClockCmd(RCC_PORT_UART, ENABLE);     
 
     /* Connect PXx to USARTx_Rx */
     GPIO_PinAFConfig(GPIO_PORT_RX, GPIO_PIN_SOURCE_RX, GPIO_AF_RX_PIN);
     
  /* Configure USART Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_PIN_RX;
  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_Init(GPIO_PORT_RX, &GPIO_InitStructure);
     
     
     
     /* USART configuration */
   USART_Init(USART_X, &USART_InitStructure);     
     /* Enable USART */
  USART_Cmd(USART_X, ENABLE);
     USART_ITConfig(USART_X, USART_IT_RXNE | USART_IT_ERR, ENABLE);
     BufferTxFree = 1;
  return 1;
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//ok
/**
  * @brief  This function handles USART1 global interrupt request.
  * @param  None
  * @retval None
  */
void USART1_IRQHandler(void)
{
     DEBUG_ON();
  if(USART_GetITStatus(USART_X, USART_IT_RXNE) != RESET)
  {
          
    /* Read one byte from the receive data register */
          RxBuf[RxBufWrIdx++] = USART_ReceiveData(USART_X) & 0xFF;
          if(RxBufWrIdx >= RX_BUF_LEN) {
                    RxBufWrIdx = 0;
          }
    CheckBusy();
          
  }


  if(USART_GetITStatus(USART_X, USART_IT_TXE) != RESET)
  {   
          BufferTxFree = 1;
  }
     DEBUG_OFF();
}



Outcomes