2130 views|2 replies

1w

Posts

16

Resources
The OP
 

[NUCLEO-L452RE Review] + Example of sending the value received by the serial port to the message queue [Copy link]

Continuing from the previous program, the previous program is like this. There are two tasks: one sends a message to the message queue, and the other receives the message queue and prints it. At the same time, the serial port receives an interrupt.

This time I want to add another message queue and a task to receive messages from the serial port. After the serial port receives 8 data, it will pass them to the message queue.

Since CMSIS_RTOS is a wrapper of FREERTOS, some of its functions have changed. Especially the message queue processing is very different. But I think CMSIS_RTOS is simple and has a promising future. So I will continue to use CMSIS_RTOS.

Please see the following article for the difference between the two:

en.DM00105262(1).pdf (731.26 KB, downloads: 2)

As for why I added a queue and a task this time, I think that the operating system uses it to solve problems for me, so now I want to run three tasks, one interrupt, and two message queues. If it can't run, it means it's not a good system.

Add the following statement in the serial port interrupt completion callback function:

/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	uint8_t i;
	HAL_UART_Transmit(&huart2, uart2_rxbuf, 1, 100);    // 把收到的字节原样发送出去
	for(i=0;i<8;i++)
	{
	osMessagePut(myQueue02Handle,uart2_rxbuf[i],osWaitForever);
	}
	HAL_UART_Receive_IT(&huart2, uart2_rxbuf, 1);       // 重新注册一次,要不然下次收不到了
}

Add the following statement in the new task:

void StartTask04(void const * argument)
{
  /* USER CODE BEGIN StartTask04 */
	osEvent evt;
	uint8_t queue_buffer[10];
  uint8_t queue_count;
	
	/* Infinite loop */
  for(;;)
  {
    evt = osMessageGet(myQueue02Handle,osWaitForever);
		if(queue_count < 8)
		{
	       queue_buffer[queue_count] = evt.value.v;
         ++queue_count;
        if(queue_count == 8)
        {
					printf("the message is trainslate...");
				}					
		}
		
		
		osDelay(1);
  }
  /* USER CODE END StartTask04 */
}

Set the breakpoint before the printf line. Run and check the sending and receiving, it is correct!

This is what I sent: 01 03 00 01 00 02 00 11

This post is from stm32/stm8

Latest reply

Thank you for sharing, looking forward to the follow-up!   Details Published on 2020-12-29 22:36
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 

1w

Posts

204

Resources
2
 

ST NUCLEO-L452RE review

Summary post: https://bbs.eeworld.com.cn/thread-1151850-1-1.html

This post is from stm32/stm8
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
Personal signature

玩板看这里:

https://bbs.eeworld.com.cn/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 

7452

Posts

2

Resources
3
 

Thank you for sharing, looking forward to the follow-up!

This post is from stm32/stm8
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list