cancel
Showing results for 
Search instead for 
Did you mean: 

Receive interrupt problem in STM32F103ZET6

ehsan2754
Associate II
Posted on February 07, 2016 at 22:52

Hello guys,

I 'm a new STM32 user that started using and learning STM32 MCUs developing .

I have circuit that I have a usart connection at usart2.

I can transmit data from MCU perfectly and also I can receive data easily but after a few receiving data from the usart , my receive interrupt doesn't run.

In addition , my project generated by STMCUBEMx.

my code is :

''

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

__HAL_UART_FLUSH_DRREGISTER(&huart2);

HAL_UART_Transmit(&huart2,(_8bit_var*)''  interrupt 1  '',sizeof(''  interrupt 1  ''),100);

HAL_UART_Receive_IT(&huart2,data,5);

}

int main(void)

{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */

  HAL_UART_Receive_IT(&huart2,data,5);

  //int cun = 0;

HAL_GPIO_WritePin(BT_KEY_GPIO_Port,BT_KEY_Pin,GPIO_PIN_RESET);

HAL_GPIO_WritePin(LED3_GPIO_Port,LED3_Pin,GPIO_PIN_SET);

HAL_GPIO_WritePin(LED4_GPIO_Port,LED4_Pin,GPIO_PIN_SET);

HAL_Delay(500);

  /* USER CODE END 2 */

  /* Infinite loop */

  /* USER CODE BEGIN WHILE */

  while (1)

  {

 HAL_GPIO_TogglePin(LED3_GPIO_Port,LED3_Pin);

delay_ms(100);   //works exactly like HAL_Delay(); 

HAL_GPIO_TogglePin(LED4_GPIO_Port,LED4_Pin);

delay_ms(100);

HAL_UART_Transmit(&huart2,data,5,100);

delay_ms(20);

int cu;

for (cu = 0;cu <5;cu++)

{

data[cu] = 0;

}

}

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

if (HAL_GPIO_ReadPin(S4_GPIO_Port,S4_Pin)==GPIO_PIN_RESET)

{

HAL_GPIO_WritePin(BT_KEY_GPIO_Port,BT_KEY_Pin,GPIO_PIN_SET);

HAL_UART_Transmit(&huart2,(_8bit_var*)''  mydata  '',sizeof(''  mydata  ''),100);

}

else{

HAL_UART_Transmit(&huart2,(_8bit_var*)''    our data   '',sizeof(''    our data   ''),100);

}

  }

  /* USER CODE END 3 */

}

''  

#stm32f103 #uart #stm32f103 #stm32 #no-hablo-hal #usart
6 REPLIES 6
Posted on February 08, 2016 at 02:52

And is there an IRQHandler calling into the HAL?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ehsan2754
Associate II
Posted on February 08, 2016 at 11:29

No,I didn't use this.

what is this function?

could you explain what is it?

I know it's some thing related to an interrupt but  I don't now what exactly it do?

ehsan2754
Associate II
Posted on February 14, 2016 at 18:12

who can answer me?

is there s.b that can do me a favor and solve my problem

?!?
Posted on February 14, 2016 at 18:47

Perhaps you can review the example directories provided with Cube?

You'd presumably have some of the initialization code enable the NVIC, and then your stm32f1xx_it.c file would need to have a handler to call back into the HAL library to do the callback/dispatch.

void USART2_IRQHandler(void)
{
HAL_UART_IRQHandler(&husart2);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ehsan2754
Associate II
Posted on February 14, 2016 at 20:23

Thank you Clive1.

I mix up each time I check up the examples included in cube.

the uart examples even didn't used HAL_UART_RECIVEIT().

it has some thing like BSD led ...? which is not understandable for me. 

Posted on February 14, 2016 at 21:18

CubeMX\STM32Cube_FW_F1_V1.2.0\Projects\STM32VL-Discovery\Examples\UART\UART_TwoBoards_ComIT\Src\main.c

BSD LED? Blue Screen of Death?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..