cancel
Showing results for 
Search instead for 
Did you mean: 

MB1034B STM32F0DISCOVERY problem on UART1 PA10

matteo239955_st
Associate II
Posted on September 07, 2012 at 09:01

I'm using STM32F0DISCOVERY

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

Here my initialization:

&sharpdefine RCC_PORT_RX RCC_AHBPeriph_GPIOA

&sharpdefine GPIO_PORT_RX GPIOA

&sharpdefine GPIO_PIN_RX GPIO_Pin_10

&sharpdefine GPIO_PIN_SOURCE_RX GPIO_PinSource10

&sharpdefine GPIO_AF_RX_PIN       GPIO_AF_1

&sharpdefine RCC_PORT_UART RCC_APB2Periph_USART1

&sharpdefine USART_X USART1

&sharpdefine RCC_PORT_DEBUG RCC_AHBPeriph_GPIOC

&sharpdefine GPIO_PORT_DEBUG GPIOC

&sharpdefine GPIO_PIN_DEBUG GPIO_Pin_8

&sharpdefine DEBUG_ON()   GPIO_SetBits  ( GPIO_PORT_DEBUG, GPIO_PIN_DEBUG )

&sharpdefine 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();

}

#stm32f0
3 REPLIES 3
frankmeyer9
Associate II
Posted on September 07, 2012 at 09:53

I miss something like this in your code:

    /* Interrupt at reception */

    USART_ITConfig (USART1, USART_IT_RXNE, ENABLE);

matteo239955_st
Associate II
Posted on September 07, 2012 at 10:15

USART_ITConfig(USART_X, USART_IT_RXNE | USART_IT_ERR, ENABLE);

Exacly the same effect: No interrupt...

matteo239955_st
Associate II
Posted on September 07, 2012 at 10:41

It's All OK!!!

In other part of the software I call USART_Cmd(USART_X, DISABLE); 

and then USART_Cmd(USART_X, ENABLE);

But when I disable the UART the configuration of the Interrupt is miss...

This Line is NOT CORRECT:

USART_ITConfig(USART_X, USART_IT_RXNE | USART_IT_ERR, ENABLE);

THIS IS CORRECT

USART_ITConfig(USART_X, USART_IT_RXNE, ENABLE);

Thank to ALL