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.
Fork of Hat_Board_v5 by
main.cpp
- Committer:
- drnow
- Date:
- 2014-03-20
- Revision:
- 2:3a8cd127b72a
- Parent:
- 1:2efeed26d93a
- Child:
- 3:8334f137c151
File content as of revision 2:3a8cd127b72a:
//Hat Board Test by James Cooke 3/18/2014
//Goal of program: read and output data from LIS3DH accelerometer
//Started with Si_4088_PC working program: able to get data from Si1142 on new hat board
// Check PS_ADC_COUNTER. It's probably wrong.
#include "mbed.h"
#include "SI_LIS.h"
#include <time.h>
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
Serial pc(USBTX,USBRX);
DigitalIn int_pin(p8);
Timer t;
int reading_IR,reading_660,LSB,MSB;
char rx_data[4];
char accel_data[6];
char temp_val;
short int temp_dataX; // short int: 16 bits. This allows easy negative results
short int temp_dataY; // short int: 16 bits. This allows easy negative results
short int temp_dataZ; // short int: 16 bits. This allows easy negative results
float t_msec;
int main()
{
unsigned char LowB_IR,HighB_IR,LowB_660,HighB_660;
myled4 = 0; // ODD: if this line not included, there is a compiler "internal error"
pc.baud(230400);
Init_Accel(); // starts LIS3DH
restart(); // starts Si1142
wait_ms(30);
command (PS_AUTO); //start measuring
wait (0.5);
while(1) {
if(!int_pin) {
myled3 = !myled3; // LED on mbed, to follow along
t.reset();
t.start();
write_reg(IRQ_STATUS,0x04); // clear the interrupt.
read_reg2(PS1_DATA0);
LowB_IR = rx_data[0];
HighB_IR = rx_data[1];
LowB_660 = rx_data[2];
HighB_660 = rx_data[3];
reading_IR = (HighB_IR * 256) + LowB_IR;
reading_660 = (HighB_660 * 256) + LowB_660;
pc.printf ("%d, %d, ", reading_IR,reading_660);
Get_Accel_Reg_6 (0x28);
temp_dataX = (accel_data[1] * 256) + accel_data[0];
pc.printf ("%d, ",temp_dataX);
temp_dataY = (accel_data[3] * 256) + accel_data[2];
pc.printf ("%d, ",temp_dataY);
temp_dataZ = (accel_data[5] * 256) + accel_data[4];
pc.printf ("%d, ",temp_dataZ);
t.stop();
t_msec = t.read() * 1000;
printf("%4.1f msec\n", t_msec);
}
}
}
/*
Notes on RJ-45: Pin 1: Vcc Pin 2: GND Pin 3: SDA > 9 on 4088
Pin 4: SCL >> 10 on 4088 Pin 6: INT > 8 on 4088
Bluetooth: Tx on 4088: Pin 37 >> RX Rx on 4088: Pin 31 >> TX
PC COMM port on Square board: 12
*/
