ADXL362 程序

直接上程序:

/**************************************************************************************************
 * @fn      HalLcd_HW_WaitUs
 *
 * @brief   wait for x us. @ 32MHz MCU clock it takes 32 "nop"s for 1 us delay.
 *
 * @param   x us. range[0-65536]
 *
 * @return  None
 **************************************************************************************************/
void Delay_us(uint16 microSecs)
{
  while(microSecs--)
  {
    /* 32 NOPs == 1 usecs */
    asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
    asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
    asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
    asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
    asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
    asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
    asm("nop"); asm("nop");
  }
}
void ADXL362_Write_Reg(uchar Addr0,uchar Data0)
{
    G_CS = 0;
    CS_OLED = 1;
    Delay_us(5);
    SPI_Write_one_reg(0x0A);
    SPI_Write_one_reg(Addr0);
    SPI_Write_one_reg(Data0);
    Delay_us(5);
    G_CS = 1;
}


uint8 ADXL362_Read_Reg(uchar Addr1)
{
    uint8 Data1;
    
    G_CS = 0;
    CS_OLED = 1;
   Delay_us(5);
    SPI_Write_one_reg(0x0B);
    SPI_Write_one_reg(Addr1);
    SPI_Write_one_reg(0x00);
   Delay_us(5);
    Data1 = temp;
    G_CS = 1;
    return Data1;
}
void ADXL362_Burst_Read_Reg(uint8 addr2, uint8 byte, uint8 *data)
{
    uint8 i;
    G_CS = 0;
    CS_OLED = 1;
    Delay_us(5);
    SPI_Write_one_reg(0x0B);
    SPI_Write_one_reg(addr2);
        
    for(i=0;i<byte;i++)
    {
        SPI_Write_one_reg(0x00);
        Delay_us(5);
        SPI_Read_one_reg(data);
        //SPI_Write_one_reg(0x00);
        //*data = temp;
        data++;
	Delay_us(5);
    }
   
    G_CS = 1;
}

void ADXL362_FIFO_read_byte( uint8 byte, uint8 *data)
{ 
    uint8 i;
    G_CS = 0;
    CS_OLED = 1;
    Delay_5us0();
    SPI_Write_one_reg(0x0D);
    for(i=0;i<byte;i++)
    {
        SPI_Write_one_reg(0x00);
        Delay_5us0();
        SPI_Read_one_reg(data);
        data++;
    }
    G_CS = 1;
}

void Delay_5us0(void)
{
     asm("nop");//fcpu 16MHz 时
     asm("nop");
     asm("nop");
     asm("nop");
     asm("nop");
}



void ADXL362Init(void)
{
    P0SEL &= ~ 0x40;//cs pin
    P0DIR |= 0x40;
   
  //HalInitSPI();
    InitAlgorithmParameters_Tap();
    ADXL362_Write_Reg(0x1F,0x52);   // software reset
    Delay_ms(20);
    ADXL362_Write_Reg(0x20,0x1F);   // 0x20 THRESH_ACT_L
    ADXL362_Write_Reg(0x21,0x00);   // 0x21 THRESH_ACT_H
    ADXL362_Write_Reg(0x22,50);   // 0x22 TIME_ACT
    ADXL362_Write_Reg(0x23,0x09);   // 0x23 THRESH_INACT_L
    ADXL362_Write_Reg(0x24,0x00);   // 0x24 THRESH_INACT_H
    ADXL362_Write_Reg(0x25,0x01);   // 0x25 TIME_INACT_L
    ADXL362_Write_Reg(0x26,0x00);   // 0x26 TIME_INACT_H
    ADXL362_Write_Reg(0x27,0x03);   // 0x27 ACT_INACT_CTL   参考模式
    //ADXL362_Write_Reg(0x28,0x00);   // 0x28 FIFO_CONTROL
    //ADXL362_Write_Reg(0x29,0x80);   // 0x29 FIFO_SAMPLES
    ADXL362_Write_Reg(0x28,0x01);   // 0x28 FIFO_CONTROL  Stream mode  0x09
    ADXL362_Write_Reg(0x29,0x33);   // 0x29 FIFO_SAMPLES  0xfe--> 510 byte
    ADXL362_Write_Reg(0x2A,0x84);   // 0x2a INTMAP1  Data_ready 映射到 Int1,下降沿
    ADXL362_Write_Reg(0x2B,0x90);   // 0x2b INTMAP2  avtivity 映射到Int2,下降沿
    ADXL362_Write_Reg(0x2C,0x82);   // 0x2c FILTER_CTL  0x82 50hz 0x84 200hz
    
    ADXL362_Read_Reg(0x0B);
      
    ADXL362_Write_Reg(0x2D,0x02);   // 0x2d POWER_CTL  Measurement mode.

    Delay_ms(200);
    ADXL362_Read_Reg(0x00);
        ADXL362_Burst_Read_Reg(0x0e,6,databuf);
        
     //ADXL362_Write_Reg(0x2D,0x00);   //
}





阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/haozi0_0/article/details/49890565
文章标签: C ADXL362
个人分类: C 语言学习
想对作者说点什么? 我来说一句

ADXL362驱动程序

2017年08月19日 10KB 下载

ADXL362中文数据手册

2018年04月08日 1.03MB 下载

ADXL362 STM32F103 SPI通讯

2017年08月12日 6.21MB 下载

没有更多推荐了,返回首页

不良信息举报

ADXL362 程序

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭