0
1

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 5 years have passed since last update.

Raspberry Pi > C > RPi_i2c_comm_180227: v0.4 > GPIOピンのレベル設定と、レベル読取まで

Last updated at Posted at 2018-03-01
Raspberry Pi 2 Model B (以下RPi)
Raspbian Jessie
Python 2.7.9

I2C通信の実装をしようとしている。
その前段階として、SCLのクロック出力を行ってみる。

code v0.4

v0.4 @ GitHub

処理概要

  • GPIO26に対してクロックを出力する
    • 5クロック
    • およそ200usec
      • 最初: 260usec
      • 以降: 160usec
  • GPIO05の値を読取る
    • gpio readallコマンドでHレベルを確認

ファイル構成

  • RPi_i2c_comm_180227.c
    • メインプログラム
  • wait_msec_nsec_180301.cと.h
    • 待ち処理のための関数

RPi_i2c_comm_180227.cのmain()

RPi_i2c_comm_180227.c
...
int main(){
    int loop;
    int pinlvl; // pin level

    // 1. output clock at [GPIO_SCL]
    gpio_setExport(GPIO_SCL, /* bfOn=*/true);
    gpio_setDirection(GPIO_SCL, /* bfOut=*/true);        
    for(loop=0; loop<5; loop++) {
        gpio_setLevel(GPIO_SCL, GPIO_HIGH);
        Wait_about200usec();
        gpio_setLevel(GPIO_SCL, GPIO_LOW);
        Wait_about200usec();
    }
    gpio_setExport(GPIO_SDA, /* bfOn=*/false);

    // 2. read at [GPIO05]
    gpio_setExport(5, /* bfOn=*/true);
    pinlvl = gpio_getLevel(5);
    printf("SDA:%d\n", pinlvl);
    gpio_setExport(5, /* bfOn=*/false);

    return 0;
}
$ gcc RPi_i2c_comm_180227.c wait_msec_nsec_180301.c
$ ./a.out 
SDA:1

qiita.png

関連

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?