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.
Accelerometro_SerialPlot.cpp
- Committer:
- domemort
- Date:
- 2021-11-03
- Revision:
- 1:dc6884f965e1
File content as of revision 1:dc6884f965e1:
#include "mbed.h"
SPI acc(D11, D12, D13);
DigitalOut cs(D7);
Serial pc(USBTX, USBRX);
char buffer[6];
int16_t data[3];
float x,y,z;
unsigned char *chptr;
void sendFloat(float);
int main(){
pc.baud(115200);
cs=1;
acc.format(8,3);
acc.frequency(2000000);
cs=0;
acc.write(0x31);
acc.write(0x0B);
cs=1;
cs=0;
acc.write(0x2D);
acc.write(0x08);
cs=1;
while (1){
wait(0.01);
cs=0;
acc.write(0x80|0x40|0x32);
for (int i=0; i<=5; i++){
buffer[i]=acc.write(0x00);
}
cs=1;
data[0] = buffer[1]<<8 | buffer[0];
data[1] = buffer[3]<<8 | buffer[2];
data[2] = buffer[5]<<8 | buffer[4];
x = 0.004*data[0];
y = 0.004*data[1];
z = 0.004*data[2];
pc.putc(0xAA);
pc.putc(0xBB);
sendFloat(x);
sendFloat(y);
sendFloat(z);
}
}
void sendFloat (float value){
chptr = (unsigned char*) &value;
for (int i=0; i<4; i++)
pc.putc(*(chptr+i));
}