Hello Amit Dhand ,
I test on my side , these code can work well on my side.

Which chip do you used ?
I recommend you create a new project, then copy and paste these code into it , build, check whether can work.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------