Today we try to write a small program on DK-S7G2 development
kit. There are two bicolor LED's(Green and Red) comprising four LED's (LED1-
Green and Red, LED2 - Green and Red). Before going into deep, I suggest you to
download DK-S7G2
user manual.
Open the development kit user manual and go to Connectivity chapter ->User Led's section.
You can see the GPIO connections to each LED. Please see the below table for corresponding
GPIO connections
Pin
|
Description
|
GPIO
|
LED1
|
Green
|
P807(p8_7)
|
LED1
|
Red
|
P808(p8_8)
|
LED2
|
Green
|
P809(p8_9)
|
LED2
|
Red
|
P810(p8_10)
|
Follow the below steps to start a project.
1. Download and install E2Studio
6.2.0
2. Open E2Studio and create a workspace.
3. After that goto File->New->Synergy C/C++ Project
4. A window will open and Select Renesas Synergy C
executable project and click Next
5. In the project name field give the project name(Example
LedBlink) click next, you will see the below screen, check the details and
development kit details should match your board and device. Click Next
6. Select BSP and click Finish and now your project is
created with hal_entry.c source file.
7. If you are using BSP package the LED pins are already
muxed to GPIO and you no need to do basic GPIO settings you can directly use
the BSP functions to turn on and off the LED. All the GPIO details are present
in r_ioport_api.h file.
8. If you want to Turn on the green LED1 give this below
line in hal_entry.c file main() function.
void hal_entry(void)
{
/* TODO: add your own
code here */
while(1)
{
g_ioport.p_api->pinWrite(IOPORT_PORT_08_PIN_07, IOPORT_LEVEL_HIGH);
}
}
Now you have able to turn on the LED. We will see how to
blink the LED(periodic Turn On and OFF). We don't know the exact delay in the
for loop so the below code you won't be able to see the blinking effect as it
happens very fast.
void hal_entry(void)
{
/* TODO: add your own
code here */
while(1)
{
for (i = 0; i < 0x100E6; i++)
g_ioport.p_api->pinWrite(IOPORT_PORT_08_PIN_07, IOPORT_LEVEL_LOW);
for ( i = 0; i < 0x100E6; i++)
g_ioport.p_api->pinWrite(IOPORT_PORT_08_PIN_07, IOPORT_LEVEL_HIGH);
}
}
Now we will see the actual delay implementation say like 1
Sec delay between each On and OFF operation so that you can see LED is really
blinking .
void hal_entry(void)
{
/* TODO: add your own
code here */
while(1)
{
g_ioport.p_api->pinWrite(IOPORT_PORT_08_PIN_07, IOPORT_LEVEL_LOW);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_SECONDS);
g_ioport.p_api->pinWrite(IOPORT_PORT_08_PIN_07, IOPORT_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_SECONDS);
}
}
Now compile the code and Run the program and you will see the LED blinking.
Now see the above code , lines which I have highlighted in red colour text. As we already said that we
are going to use SSP package which contains Renesas BSP. I have used the BSP
functions to give the exact 1 second delay between each ON and OFF operation.
R_BSP_SoftwareDelay(uint32_t delay, bsp_delay_units_t units)
takes two arguments. Below are the
values which we can give to 2nd argument.
typedef enum
{
BSP_DELAY_UNITS_SECONDS =1000000, ///< Requested delay amount is in seconds
BSP_DELAY_UNITS_MILLISECONDS = 1000, ///< Requested delay amount is in
milliseconds
BSP_DELAY_UNITS_MICROSECONDS = 1 ///< Requested delay amount is in
microseconds
} bsp_delay_units_t;
In the above code in order to get 1 second delay I have given
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_SECONDS) , 1 is number of seconds and
second argument is units.
Thank You