# xEventGroupSetBitsFromISR and xEventGroupWaitBits call order

**URL:** <https://forums.freertos.org/t/xeventgroupsetbitsfromisr-and-xeventgroupwaitbits-call-order/15319>\
**Category:** Kernel\
**Created:** [June 24, 2022, 6:50am UTC](https://forums.freertos.org/t/xeventgroupsetbitsfromisr-and-xeventgroupwaitbits-call-order/15319 "2022-06-24T06:50:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elevenxiang](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/elevenxiang/32/2641_2.png) [@elevenxiang](https://forums.freertos.org/u/elevenxiang)\
**Post date:** [June 24, 2022, 6:50am UTC](https://forums.freertos.org/t/xeventgroupsetbitsfromisr-and-xeventgroupwaitbits-call-order/15319/1 "2022-06-24T06:50:30Z")

</div>

Hi,

I hit a situation that ISR will always call xEventGroupSetBitsFromISR first, and then task call xEventGroupWaitBits, so the task will never be waken up.

So I wonder it is normal ?

is there any method that task can always wake up even the notification has been sent before ?

Thanks

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [June 24, 2022, 7:09am UTC](https://forums.freertos.org/t/xeventgroupsetbitsfromisr-and-xeventgroupwaitbits-call-order/15319/2 "2022-06-24T07:09:37Z")

</div>

If a task makes a call to wait for a bit that is already set then it should return immediately, without ever blocking.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [June 24, 2022, 7:18am UTC](https://forums.freertos.org/t/xeventgroupsetbitsfromisr-and-xeventgroupwaitbits-call-order/15319/3 "2022-06-24T07:18:53Z")

</div>

Also, can you share your code snippets where you set and wait for bits?

---

<div class="post-metadata">

**Author:** ![elevenxiang](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/elevenxiang/32/2641_2.png) [@elevenxiang](https://forums.freertos.org/u/elevenxiang)\
**Post date:** [June 24, 2022, 7:34am UTC](https://forums.freertos.org/t/xeventgroupsetbitsfromisr-and-xeventgroupwaitbits-call-order/15319/4 "2022-06-24T07:34:58Z")

</div>

if so, that would be weird.

I need check the code for more detail

Thank you so much

---

<div class="post-metadata">

**Author:** ![elevenxiang](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/elevenxiang/32/2641_2.png) [@elevenxiang](https://forums.freertos.org/u/elevenxiang)\
**Post date:** [June 24, 2022, 8:14am UTC](https://forums.freertos.org/t/xeventgroupsetbitsfromisr-and-xeventgroupwaitbits-call-order/15319/5 "2022-06-24T08:14:12Z")

</div>

Hi rtel,

I checked the code, and still not found any logic errors.

So I changed the type to binary semaphore, and use xSemaphoreTake() & xSemaphoreGiveFromISR(), then it works 🙂

I am not very familiar with FreeRTOS history, is it related with OS version ?

Thanks

---

<div class="post-metadata">

**Author:** ![elevenxiang](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/elevenxiang/32/2641_2.png) [@elevenxiang](https://forums.freertos.org/u/elevenxiang)\
**Post date:** [June 24, 2022, 8:32am UTC](https://forums.freertos.org/t/xeventgroupsetbitsfromisr-and-xeventgroupwaitbits-call-order/15319/6 "2022-06-24T08:32:34Z")

</div>

Hi aggarg,

Simplify the code flow:

1. init stage  
event = = xEventGroupCreate()

2. set  
ISR {  
…  
xEventGroupSetBitsFromISR(event, BITS, NULL);  
}

3. wait in task  
Task {  
xEventGroupWaitBits(event, BITS, …)  
}

Thanks
