Ryusuke Iwata
/
HEPTA-Sat-Lite_Detect_z-axis
Detecting z-axis acceralation
Revision 0:99043f8d668d, committed 2021-08-03
- Comitter:
- RyusukeIwata
- Date:
- Tue Aug 03 06:57:44 2021 +0000
- Commit message:
- first commit;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Aug 03 06:57:44 2021 +0000 @@ -0,0 +1,63 @@ +//icm20601 最新版 +#include "mbed.h" +Serial pc(USBTX, USBRX); +I2C i2c(PB_7,PB_6); +DigitalOut conv(PA_4); + +const int addr_accel_gyro = 0xD0; +char cmd[2]; +char data[1]; +char xh[1]; +char xl[1]; + +int main() +{ + conv = 1; + i2c.frequency(100000); + char cmdd; + wait(2); + data[0] = 0x75; + i2c.write(addr_accel_gyro,data,1); + i2c.read(addr_accel_gyro|0x01,xh,1); + pc.printf("xh = 0x%02X\r\n",xh[0]); + while(1){ + cmdd = pc.getc(); + if(cmdd == 'a'){ + data[0] = 0x75; + i2c.write(addr_accel_gyro,data,1); + i2c.read(addr_accel_gyro|0x01,xh,1); + pc.printf("xh = 0x%02X\r\n",xh[0]); + + cmd[0]=0x6B; + cmd[1]=0x00; + i2c.write(addr_accel_gyro,cmd,2); + + cmd[0]=0x6C; + cmd[1]=0x00; + i2c.write(addr_accel_gyro,cmd,2); + + + cmd[0] = 0x37; + cmd[1] = 0x02; + i2c.write(addr_accel_gyro,cmd,2); + + + while(1) { + data[0] = 0x3F; + i2c.write(addr_accel_gyro,data,1); + i2c.read(addr_accel_gyro|0x01,xh,1); + data[0] = 0x40; + i2c.write(addr_accel_gyro,data,1); + i2c.read(addr_accel_gyro|0x01,xl,1); + //pc.printf("xh = 0x%02X,xl = 0x%02X\r\n",xh[0],xl[0]); + double acc_ax = short((xh[0]<<8) | (xl[0])); + double AX = (acc_ax)*4/32764*9.81; + pc.printf("AZ = %f\r\n",AX); + wait(0.5); + } + } + } + + + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Aug 03 06:57:44 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file