Slight Mod

Dependencies:   mbed-dsp mbed

Fork of Hat_Board_v5 by John Scharf

main.cpp

Committer:
drnow
Date:
2014-03-20
Revision:
0:34bad5aca893
Child:
1:2efeed26d93a

File content as of revision 0:34bad5aca893:

//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_2_data[2];
char        temp_val;
char        accel_data;   // for getting 8-bit value from accelerometer
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

/* From AccelWaveForms
In Loop:
            Get_Accel_Register(0x2A, LIS_Addr);  //Y Data Low
            LSB = Accel_Data;
            Get_Accel_Register(0x2B, LIS_Addr);  //Y Data High
            MSB = Accel_Data;
            temp_dataY = (MSB * 256) + LSB;

            Get_Accel_Register(0x2C, LIS_Addr);  //Z Data Low
            LSB = Accel_Data;
            Get_Accel_Register(0x2D, LIS_Addr);  //Z Data High
            MSB = Accel_Data;
            temp_dataZ = (MSB * 256) + LSB;
*/

int main()
{
    unsigned char LowB_IR,HighB_IR,LowB_660,HighB_660;
    char    Reg_Val = 0x00;
    char    Reg_Num;

    myled4 = 0;  // ODD: if this line not included, there is a compiler "internal error"
    pc.baud(230400);
    i2c_start();        //sets i2c bus at 400,000.  Also set by photodiode setup/reset

    Reg_Num = 0x20; // CTRL_REG1
    Reg_Val = 0x57; // Nib 1 of 0101: Normal mode, 100 Hz;  Nib 2 of 0111: Normal mode, XYZ enabled
    Init_Accel (Reg_Num, Reg_Val);

    wait(0.050);    // Delay needed, or 2nd write doesn't work

    Reg_Num = 0x21; // CTRL_REG2
    Reg_Val = 0xA0; // 7-6 10: Normal filter mode;  5-4 10: Cut off freq; 3-0 0000: bypass interrupts
    // High-pass filter bits 5-4: @ 100 Hz:  00 - 2Hz   01 - 1Hz   10- 0.5Hz   11- 0.2Hz
    Init_Accel (Reg_Num, Reg_Val);
    wait(0.050);    // Delay needed?

    pc.printf ("Hello\n");

    Get_Accel_Register (0x0F);
    pc.printf ("I am: %x",accel_data);  //in hex

    while (1) {
        Get_Accel_Register(0x28);  //X Data Low
        LSB = accel_data;
        Get_Accel_Register(0x29);  //X Data High
        MSB = accel_data;
        temp_dataX = (MSB * 256) + LSB;
        pc.printf ("%d ",temp_dataX);  
        
        Get_Accel_Register_2 (0x28);
        LSB = accel_2_data[0];
        MSB = accel_2_data[1];
        temp_dataX = (MSB * 256) + LSB;
        pc.printf ("%d\n",temp_dataX);  

/*
void Get_Accel_Register_2 (char Reg_Num) // Read 2 registers
{
    char  reg;
    reg = Reg_Num;
    i2c.write((LIS_Addr << 1) & 0xFE, &reg, 1);
    i2c.read((LIS_Addr << 1) | 0x01, accel_2_data, 2);
}
*/        
        wait(0.02);
    }
    /*
        restart();
        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\n", reading_IR,reading_660);
            }
        }
    */

}
/*
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

*/