Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:aa97de8e628a, committed 2017-04-23
- Comitter:
- sog_yang
- Date:
- Sun Apr 23 01:04:47 2017 +0000
- Child:
- 1:510ee396d140
- Commit message:
- AS7000 ARM mBedOS C++ Driver
Changed in this revision
| AS7000.cpp | Show annotated file Show diff for this revision Revisions of this file |
| AS7000.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/AS7000.cpp Sun Apr 23 01:04:47 2017 +0000
@@ -0,0 +1,61 @@
+#include "AS7000.h"
+#include "mbed.h"
+
+DigitalOut AS7000_GPIO8(p5); //NNN50-P5 map to GPIO-8 for AS7000 on/off
+DigitalInOut AS7000_INT(p4); //NNN50-P4 GPIO-5 for AS7000 INT
+
+
+AS7000::AS7000(PinName SDA, PinName SCL) : _i2c(SDA,SCL){
+ //Set I2C fast and bring reset line high
+ _i2c.frequency(100000);
+ address = AS7000Address;
+
+ AS7000_INT.mode(PullNone);
+
+ AS7000_INT.output();
+
+ AS7000_GPIO8.write(1); // Power OFF AS7000
+ AS7000_INT.write(1); // AS7000 GPIO OUTPUT LOW
+ AS7000_INT.input();
+ wait_ms(100);
+}
+
+void AS7000::enable(void){
+ char cmd[2];
+
+ AS7000_GPIO8.write(0); //Power ON AS7000
+ wait_ms(280); //Wait for > 250ms for booting
+
+
+ cmd[0] = AS7000_STARTUP; //0x04;
+ cmd[1] = 0x02;
+ _i2c.write(address, cmd, 2);
+ wait_ms(35);
+
+}
+
+void AS7000::update(void){
+ hrm.transaction_id = rawdata[0];
+ hrm.status = rawdata[1];
+ hrm.hreat_rate = rawdata[2];
+ hrm.signal_QA = rawdata[3];
+ hrm.LED_current = ((rawdata[4]<<8)+rawdata[5]);
+ hrm.SYNC = rawdata[6];
+}
+
+void AS7000::hr_only(void){
+ char cmd[2];
+ cmd[0] = HR_ONLY;
+ if(AS7000_INT == 0) {
+ _i2c.write(address, cmd, 1);
+ _i2c.read(address, rawdata, 7, false);
+ wait_ms(10);
+ update();
+ }
+ printf("*HR=%03d#", hrm.hreat_rate);
+ //printf("\n");
+ //printf("transaction_id:=%03d# status:=%03d# hreat_rate:=%03d#", hrm.transaction_id,hrm.status,hrm.hreat_rate);
+ //printf("signal_QA:=%03d# LED_current:=%6.2f# SYNC:=%03d#", hrm.signal_QA,hrm.LED_current,hrm.SYNC);
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/AS7000.h Sun Apr 23 01:04:47 2017 +0000
@@ -0,0 +1,63 @@
+#ifndef AS7000_H
+#define AS7000_H
+
+#include "mbed.h"
+//
+#define AS7000Address 0x60
+//Register definitions
+#define AS7000_STARTUP 0x04 //4
+#define HR_ONLY 0x08 //8
+#define HR_ONLY_LEN 0x07 //7
+#define HR_REG 0x12 //18
+#define HR_LEN 21
+
+typedef struct{
+ uint8_t transaction_id;
+ uint8_t status;
+ uint8_t hreat_rate;
+ uint8_t signal_QA;
+ uint16_t LED_current;
+ uint8_t SYNC;
+ uint8_t startup_flag;
+ bool contact_detected;
+}as7000_t;
+
+
+
+
+/** Class for operating Bosch BNO055 sensor over I2C **/
+class AS7000
+{
+public:
+
+/** Create BNO055 instance **/
+ AS7000(PinName SDA, PinName SCL);
+
+ void gpio_init(void);
+ void enable (void);
+ void startup (void);
+ void hr_only (void);
+ void update (void);
+ as7000_t hrm;
+
+
+ private:
+ I2C _i2c;
+ char rx,tx[2],address; //I2C variables
+ char rawdata[22]; //Temporary array for input data values
+ char hreat_rate;
+ char startup_flag;
+
+void readchar(char location){
+ tx[0] = location;
+ _i2c.write(address,tx,1,true);
+ _i2c.read(address,&rx,1,false);
+}
+
+void writechar(char location, char value){
+ tx[0] = location;
+ tx[1] = value;
+ _i2c.write(address,tx,2);
+}
+ };
+#endif
\ No newline at end of file