AnsweredAssumed Answered

ADXL362 interfaced with Microship PIC, how to make it working ?

Question asked by SebastienFromSweden on Dec 11, 2014
Latest reply on Dec 28, 2014 by SebastienFromSweden

Dear All,

 

We can see on youtube this nice presentation of the ADXL362 :

ADXL362: Enhanced Activity Detection for System-Level Power Savings - YouTube

Would it be possible to get the source code of this project ?

I linked an ADXL362 to a PIC16f818 and didn't succeeded to make it working.

Here a pic of the project :

IMG_4016.JPGIMG_4014.JPG

Here is my code :

 


#include <stdio.h>
#include <stdlib.h>
#include <pic16f819.h>
#include "header.h"

// ACC Registers
#define ID0 0x00
#define STATUS 0x0b
#define RESET 0x1f
#define INTMAP1 0x2a
#define INTMAP2 0x2b
#define FILTER_CTL 0x2c
#define POWER_CTL 0x2d

#define WR_SPI 0x0A
#define RD_SPI 0x0B
#define DOWN 0
#define UP 1
#define CS PORTAbits.RA2

//Declaration signature function
void Delay(int);
char ACC_ReadReg( char );
void ACC_WriteReg( char, char);
char SPI_OUTPUT ( char );
void LedActivate();

void main(void) {

    char reg;

    //Set up the clock for the PIC
    IRCF2 = 0;
    IRCF1 = 0;
    IRCF0 = 1;
    IOFS = 1;

    //Set up the SPI support
    TRISAbits.TRISA1 = 0;  //LED is an output
    TRISAbits.TRISA2 = 0;  //CS is an output
    TRISBbits.TRISB1 = 1;  //SDI is an input
    TRISBbits.TRISB2 = 0;  //SDO is an output
    TRISBbits.TRISB4 = 0;  //SCK is an output

    //SPI Configuration
    SSPSTAT = 0x40;    // 0100 0000 datasheet page 72
    SSPCON = 0x31;    // 0011 0001 datasheet page 73
   
    //Switch on the LED;
    PORTAbits.RA1 = 1;

    //----------------Start ADXL362 Initialisation---------------------------

    // reset the adxl362
    Delay(500);
    //ACC_WriteReg(RESET, 0x52);
    ACC_WriteReg(0x1f, 0x52);
    Delay(500);

    //Check Reset done
    reg = ACC_ReadReg(0x00);
    reg = ACC_ReadReg(0x2c);

   // Activity datasheet detection 250mg ACT_L
    ACC_WriteReg(0x20,0xFA);
    reg = ACC_ReadReg(0x20);

     // Activity datasheet detection 250mg ACT_H
    ACC_WriteReg(0x21,0x0);
    reg = ACC_ReadReg(0x21);

    // datasheet inactivity INACT_L
    ACC_WriteReg(0x23,0x96);
    reg = ACC_ReadReg(0x23);

     // datasheet inactivity INACT_H
    ACC_WriteReg(0x24,0x0);
    reg = ACC_ReadReg(0x24);

    //Time before going in sleep mode if inactivity 30 samples or about 5 seconds
    ACC_WriteReg(0x25,0x1E);
    reg = ACC_ReadReg(0x25);

    //Put in loops mode
    ACC_WriteReg(0x27,0x3F);
    reg = ACC_ReadReg(0x27);

    // map adxl362 interrupts 2 in awake mode
    ACC_WriteReg(0x2b,0x40);
    reg = ACC_ReadReg(0x2b);

    // set adxl362 to measurement mode, ultralow noise
    ACC_WriteReg(0x2d,0x0A);
    reg = ACC_ReadReg(0x2d);

    while(1)
    {
        1==1;
    }
}

void Delay(int ms)
{
    int maxCount = ms*30/1000;
    //int maxCount=120;
    TMR0=0;
    T0CS=0;
    T0SE=0;
    PSA=0;
    PS0=1;
    PS1=1;
    PS2=1;
    while(maxCount--)
    {
        while(!TMR0IF);
        TMR0IF=0;
        Count++;
    }
}

//Read SPI bus
char ACC_ReadReg( char reg )
{
    CS = DOWN;
    //SPI_OUTPUT(RD_SPI);
    SPI_OUTPUT(0x0B);
    SPI_OUTPUT(reg);
    CKP=0;
    char val = SPI_OUTPUT(0x00);
    CS = UP;
    return (val);
}

//Write SPI bus
void ACC_WriteReg( char reg, char cmd )
{
    CS = DOWN;
    //SPI_OUTPUT(WR_SPI);
    SPI_OUTPUT(0x0A);
    SPI_OUTPUT(reg);
    SPI_OUTPUT(cmd);
    CS = UP;
}

//Execute Reading/Writing
char SPI_OUTPUT ( char spi_byte )
{
    SSPBUF = spi_byte;
    do {}
    while(BF);
    return SSPBUF;
}

 

 

Best regards

Outcomes