I am a beginner in programming. I am using an rl78i1c board . I wanted to send uart messages every 10 second . How can I implement code with timer interrupt.
Can I get a sample code for timer interrupt.
I had experience with Arduino programming which has got a simpletimer library and function setinterval(time,ISR()) for timer interrupt. Can somebody help me with a sample code??
Hello elsa! You may want to refer to this sample code. I hope that helps. Best regards, Sai RenesasRulz Forum Moderator https://renesasrulz.com/ https://academy.renesas.com/ en-us.knowledgebase.renesas.com/
In reply to Sai:
In reply to elsa:
I recommend that you install applilet3/AP4 code generator and use that with e2 studio.
Add the code generator to RL78 project.
Click on code generator then select the serial and timer sections to set it up. (first configure Clock Generator if you didn't do it already)
UART setup is pretty simple. Make sure to select both transmit and receive AND set them both to the same settings for typical operation.
Then for timer you should add an interval timer using one of the last timer slots as shown.
For this example I have timer 7 selected as interval timer. It is set to 2ms here. This will call the r_tau0_channel7_interrupt() function in r_cg_timer_user.c every 2 ms.
But first you must start it using R_TAU0_Channel7_Start() and call EI(); somewhere in the project to enable interrupts. See r_cg_timer.c for how the timer is actually setup.
In the function call where it says to add user code, you can specify a global variable (flag). Inside the interrupt you should set this flag to some value.
Then in your main program in a while loop you can check if the flag is set to perform some operation, then change the flag afterwards.
You must click the "Generate Code" button shown for the src files to appear in the project. This should help get you started.
I recommend you select GCC for Renesas RL78 as compiler and select GNU ISO C99 or C11 for the initial project setup for most projects. Then you can use #include <stdbool.h> and use the "bool" type in your project for flags.
Finally by using the code generator like this you can easily step up to Renesas RX development in the future since the tools are very similar. (also port your code between them)