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.
Dependencies: ADXL362 mbed MPL3115A2
Revision 22:1cd3cb77ec07, committed 2018-02-27
- Comitter:
- htdoughe
- Date:
- Tue Feb 27 15:44:40 2018 +0000
- Parent:
- 21:b85d1a4f0373
- Child:
- 23:f9461117d7e3
- Commit message:
- errors but my computer's dying
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Feb 27 14:35:58 2018 +0000
+++ b/main.cpp Tue Feb 27 15:44:40 2018 +0000
@@ -82,10 +82,10 @@
}
//map of register values and names for the adxl
-char mregids[34];
-char* mregnames[34];
+char mregids[46];
+char* mregnames[46];
//populating the map
-void initmap() {
+void minitmap() {
mregids[0] = 0x00;
mregids[1] = 0x01;
mregids[2] = 0x02;
@@ -184,6 +184,9 @@
// Interface pulled from ADXL362.cpp
// ADXL362::ADXL362(PinName CS, PinName MOSI, PinName MISO, PinName SCK) :
ADXL362 adxl362(PA_0,PA_7,PA_6,PA_1);
+Serial pc(USBTX, USBRX);
+I2C i2c(PB_7, PB_6);
+MPL3115A2 MPL3115A2(&i2c, &pc);
int adxl362_reg_print(int s, int l){
//check s is between 0x00 and 0x2E
@@ -266,40 +269,43 @@
//check length > 0
printf("mpl: requires length >= 0, given %d\n\r", l);
return -1;
- }else{
+ } else {
//else do stuff
- char whoami = mpl115A2.read_reg(MPL3115A2::WHO_AM_I);
- if(whoami != 0xC4){
+ uint8_t wai = MPL3115A2::whoAmI();
+ printf("whoami = 0x%01x", wai);
+ if(wai != 0xC4) {
printf("error: WHO_AM_I is not 0xC4; exiting\n");
return -1;
- }else{
+ } else {
//now do stuff
//if length == 0, send everything from s to end of registers
//else print from s to l
// formula : range = end - start - length
// area = start + range
int stop = 0;
- if(l == 0){
+ if(l == 0) {
stop = 34;
- }else{
+ } else {
stop = s + l;
}
int in = s;
- while(in < stop){
+ while(in < stop) {
//get register name
char * name = mregnames[in]; //GET NAME
char reg = mregids[in];
- char val = MPL3115A2::i2cRead(reg); //GET REG VAL
+ uint8_t val = MPL3115A2::i2cRead((char) reg); //GET REG VAL
//print val
printf("0x%01x: %s=0x%01x\r\n", mregids[in], name, val);
in++;
- }
- }
- }
-}
+ }//while
+ }//else
+ }//else
+ return 0;
+}//print
int main() {
initmap();
+ minitmap();
adxl362.reset();
wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
adxl362.set_mode(ADXL362::MEASUREMENT);