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 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);   //
}





你可能感兴趣的:(C,语言学习,C,ADXL362)