1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Renesas RAマイコンを使ってみよう(2)~Lチカ編~

Posted at

Renesas RAマイコンを使ってみよう~e2StudioインストールからBlinkyまで~ の続きです。

今回は、LEDをチカチカさせる Blinkyプログラム(Lチカ) を1から作ってみましょう。

新規プロジェクトを作成する

ファイル⇒新規⇒Renesas C/C++ Projext⇒Renesas RA を選択します。
image.png
Renesas C/C++ Project をクリックして、Next をクリックします。
image.png
Project Name を入力し Next をクリックします。
image.png
使用するボードを選択し 次へ をクリックします。
image.png
今回も FPB-RA2E1 を選択します。
image.png
RTOS を使用しない No RTOS にします。
image.png
Bare Metal - Minimal を選択し、終了をクリックします。
image.png
以上で、ボード設定などが入ったプロジェクトが用意されました。
パースペクティブを開く をクリックします。
image.png

RA Flexible Software Package Documentation

FSPのドキュメントを見てみましょう。
梟のアイコンをクリックすると以下のページに飛びます。

image.png
今回使用する I/O Port (r_ioport) の設定を見てみましょう。

プログラムを作る

最初に Generate Project Content をクリックします。
image.png
Developer Assistance から必要なAPI関数を選択します。
Developer Assistance を開いて Call R_IOPORT_PinWrite を探します。
image.png
Call R_IOPORT_PinWrite を選択し、プログラムエリアへ貼り付けます。
image.png
status = は不要なので削除します。
image.png
pinLED1 にします。
image.png
LevelBSP_IO_LEVEL_HIGH とします。
image.png
同じく BSP_IO_LEVEL_LOW の行を作りますが、そのままでは人間の視覚では判断できないスピードで点滅するので Delay を追加します。
R_BSP_SoftwareDelay を選択します。
image.png
今回は 1000,BSP_DELAY_UNITS_MILLISECONDS としました。
image.png
以上で完成です。
image.png

LED2を追加する

LED1 と同じように LED2 を追加してみましょう。
image.png

IO設定

デバッグを行うとわかりますが、ピンの名前が逆になっていますので修正しつつ、LED2に変更し
Generate Project Content をクリックします。
image.png
image.png
image.png
プログラムも修正し、ビルド、デバッグ します。
image.png

プログラム

今回のプログラムは以下になります。

BlinkyFirst
void hal_entry(void)
{
    /* TODO: add your own code here */
    while(1){
     R_IOPORT_PinWrite(&g_ioport_ctrl, LED1,BSP_IO_LEVEL_HIGH );
     R_IOPORT_PinWrite(&g_ioport_ctrl, LED2,BSP_IO_LEVEL_HIGH );
     R_BSP_SoftwareDelay(1000, BSP_DELAY_UNITS_MILLISECONDS);
     R_IOPORT_PinWrite(&g_ioport_ctrl, LED1,BSP_IO_LEVEL_LOW );
     R_IOPORT_PinWrite(&g_ioport_ctrl, LED2,BSP_IO_LEVEL_LOW );
     R_BSP_SoftwareDelay(1000, BSP_DELAY_UNITS_MILLISECONDS);
    }
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?