このライブラリーはテストに作ったものです。近いうちに他の関数を加えた形でアップデートするつもりです。 read_8(int reg)、read_16(int reg) で レジスターregの値を8bit、16bitで読み込み、そのまま返します。受け取り側の変数をint8_t、int16_t で定義すれば正負に分かれた値を得られます。 write_8(int reg,int data)、write_16(int reg,int data)で レジスターregに8bit、16bit 書き込み、成功したら0、失敗したら1を返します。確認はread_8、read_16を用いています。 conect() でデバイスが使用可能かを調べ、見つかれば0、なければ1を返します。 reg_reset() で全てのレジスタの値を0にします。成功したら0、失敗したらその時点で処理を停止し、失敗したレジスタを返します。 レジスタは公式のデータシートに書いてあるものと文字は同じです。 もしかしたらうまく行かない関数があるかもしれません。次のアプデのときに修正予定です。
Dependents: Nucleo_L3GD20_MMA7361_Kalman
l3gd20.h@6:26002aa6f35e, 2016-09-29 (annotated)
- Committer:
- hirokimineshita
- Date:
- Thu Sep 29 08:49:09 2016 +0000
- Revision:
- 6:26002aa6f35e
- Parent:
- 5:b90e14f61ffb
- Child:
- 7:7bacf1cef92f
+a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hirokimineshita | 0:f2770227e24c | 1 | #ifndef _L3GD20_H_20150124_1526_ |
hirokimineshita | 0:f2770227e24c | 2 | #define _L3GD20_H_20150124_1526_ |
hirokimineshita | 0:f2770227e24c | 3 | |
hirokimineshita | 1:354deb9168c0 | 4 | #include "binary.h" |
hirokimineshita | 1:354deb9168c0 | 5 | |
hirokimineshita | 0:f2770227e24c | 6 | #define WHO_AM_I 0x0F |
hirokimineshita | 0:f2770227e24c | 7 | #define CTRL_REG1 0x20 |
hirokimineshita | 0:f2770227e24c | 8 | #define CTRL_REG2 0x21 |
hirokimineshita | 0:f2770227e24c | 9 | #define CTRL_REG3 0x22 |
hirokimineshita | 0:f2770227e24c | 10 | #define CTRL_REG4 0x23 |
hirokimineshita | 0:f2770227e24c | 11 | #define CTRL_REG5 0x24 |
hirokimineshita | 0:f2770227e24c | 12 | #define REFERENCE 0x25 |
hirokimineshita | 0:f2770227e24c | 13 | #define OUT_TEMP 0x26 |
hirokimineshita | 0:f2770227e24c | 14 | #define STATUS_REG 0x27 |
hirokimineshita | 0:f2770227e24c | 15 | #define OUT_X_L 0x28 |
hirokimineshita | 0:f2770227e24c | 16 | #define OUT_X_H 0x29 |
hirokimineshita | 0:f2770227e24c | 17 | #define OUT_Y_L 0x2A |
hirokimineshita | 0:f2770227e24c | 18 | #define OUT_Y_H 0x2B |
hirokimineshita | 0:f2770227e24c | 19 | #define OUT_Z_L 0x2C |
hirokimineshita | 0:f2770227e24c | 20 | #define OUT_Z_H 0x2D |
hirokimineshita | 0:f2770227e24c | 21 | #define FIFO_CTRL_REG 0x2E |
hirokimineshita | 0:f2770227e24c | 22 | #define FIFO_SRC_REG 0x2F |
hirokimineshita | 0:f2770227e24c | 23 | #define INT1_CFG 0x30 |
hirokimineshita | 0:f2770227e24c | 24 | #define INT1_SRC 0x31 |
hirokimineshita | 0:f2770227e24c | 25 | #define INT1_TSH_XH 0x32 |
hirokimineshita | 0:f2770227e24c | 26 | #define INT1_TSH_XL 0x33 |
hirokimineshita | 0:f2770227e24c | 27 | #define INT1_TSH_YH 0x34 |
hirokimineshita | 0:f2770227e24c | 28 | #define INT1_TSH_YL 0x35 |
hirokimineshita | 0:f2770227e24c | 29 | #define INT1_TSH_ZH 0x36 |
hirokimineshita | 0:f2770227e24c | 30 | #define INT1_TSH_ZL 0x37 |
hirokimineshita | 0:f2770227e24c | 31 | #define INT1_DURATION 0x38 |
hirokimineshita | 0:f2770227e24c | 32 | #define READ 0x80 |
hirokimineshita | 0:f2770227e24c | 33 | #define WRITE 0x00 |
hirokimineshita | 1:354deb9168c0 | 34 | #define X 0 |
hirokimineshita | 1:354deb9168c0 | 35 | #define Y 2 |
hirokimineshita | 1:354deb9168c0 | 36 | #define Z 4 |
hirokimineshita | 0:f2770227e24c | 37 | |
hirokimineshita | 2:de6dc4af9b75 | 38 | /** This progrum is to be easy to control L3GD20 sensor |
hirokimineshita | 3:76a16de2531d | 39 | * |
hirokimineshita | 6:26002aa6f35e | 40 | * site http://akizukidenshi.com/catalog/g/gK-06779/ |
hirokimineshita | 2:de6dc4af9b75 | 41 | */ |
hirokimineshita | 0:f2770227e24c | 42 | class l3gd20{ |
hirokimineshita | 0:f2770227e24c | 43 | private: |
hirokimineshita | 0:f2770227e24c | 44 | SPI l3gdev; |
hirokimineshita | 0:f2770227e24c | 45 | DigitalOut l3gcs; |
hirokimineshita | 1:354deb9168c0 | 46 | Serial pcdev; |
hirokimineshita | 1:354deb9168c0 | 47 | int scale; |
hirokimineshita | 0:f2770227e24c | 48 | public: |
hirokimineshita | 2:de6dc4af9b75 | 49 | /** constracta |
hirokimineshita | 3:76a16de2531d | 50 | * |
hirokimineshita | 6:26002aa6f35e | 51 | * use default parm, set to mosi,miso,sck,cs:PB_15-PB_14\n\r |
hirokimineshita | 2:de6dc4af9b75 | 52 | * SPI frequency:1000000 |
hirokimineshita | 2:de6dc4af9b75 | 53 | * SPI mode:3 |
hirokimineshita | 2:de6dc4af9b75 | 54 | */ |
hirokimineshita | 0:f2770227e24c | 55 | l3gd20(); |
hirokimineshita | 2:de6dc4af9b75 | 56 | |
hirokimineshita | 2:de6dc4af9b75 | 57 | /** constracta |
hirokimineshita | 2:de6dc4af9b75 | 58 | * only set frequency parm, set to mosi,miso,sck,cs:PB_15-PB_14 |
hirokimineshita | 2:de6dc4af9b75 | 59 | * SPI mode:3 |
hirokimineshita | 2:de6dc4af9b75 | 60 | * @param fhz SPI frequency |
hirokimineshita | 2:de6dc4af9b75 | 61 | */ |
hirokimineshita | 0:f2770227e24c | 62 | l3gd20(int fhz); |
hirokimineshita | 0:f2770227e24c | 63 | l3gd20(PinName cs,int fhz); |
hirokimineshita | 2:de6dc4af9b75 | 64 | l3gd20(PinName miso,PinName mosi,PinName sck,PinName cs,int fhz,int mode = 3); |
hirokimineshita | 0:f2770227e24c | 65 | int reg_reset(); |
hirokimineshita | 0:f2770227e24c | 66 | int conect(); |
hirokimineshita | 0:f2770227e24c | 67 | uint8_t read_8(uint8_t reg); |
hirokimineshita | 0:f2770227e24c | 68 | uint16_t read_16(uint8_t reg); |
hirokimineshita | 0:f2770227e24c | 69 | int write_8(uint8_t reg,uint8_t data); |
hirokimineshita | 1:354deb9168c0 | 70 | void s_write_8(uint8_t reg,uint8_t data); |
hirokimineshita | 0:f2770227e24c | 71 | int write_16(uint8_t reg,uint16_t data); |
hirokimineshita | 1:354deb9168c0 | 72 | int get_scale(); |
hirokimineshita | 1:354deb9168c0 | 73 | int set_scale(int dps); |
hirokimineshita | 1:354deb9168c0 | 74 | int get_temp(); |
hirokimineshita | 1:354deb9168c0 | 75 | int16_t get_rotate_by_bit(int axis); |
hirokimineshita | 1:354deb9168c0 | 76 | float get_rotate_by_rad(int axis); |
hirokimineshita | 1:354deb9168c0 | 77 | float get_rotate(int axis); |
hirokimineshita | 1:354deb9168c0 | 78 | float deg_to_rad(float deg); |
hirokimineshita | 0:f2770227e24c | 79 | }; |
hirokimineshita | 0:f2770227e24c | 80 | |
hirokimineshita | 0:f2770227e24c | 81 | #endif |