ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
adxl345.c
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15
16#include "adxl345.h"
17
19
21{
22 ADXL345_CS = 0;
23 xbuf[0] = addr | 0x80;
24 xbuf[1] = 0xFF;
26 ADXL345_CS = 1;
27 return xbuf[1];
28}
29
31{
32 ADXL345_CS = 0;
33 xbuf[0] = addr | 0xC0;
34 xbuf[1] = 0xFF;
35 xbuf[2] = 0xFF;
37 ADXL345_CS = 1;
38 return *((uint16_t *)&xbuf[1]);
39}
40
42{
43 ADXL345_CS = 0;
44 xbuf[0] = addr;
45 xbuf[1] = dat;
47 ADXL345_CS = 1;
48}
49
51 ADXL345_DataRate_t dataRate,
52 ADXL345_SPI_Wire_t spiWire,
53 ADXL345_IntActive_t intLevel,
57{
59 {
62 spiWire|intLevel|resolve|alignment|range);
63 ADXL345_WriteByte(ADXL345_REG_POWER_CTL, 0x08); // BIT3=0/1:(测量模式/待机模式);BIT2=0/1:(工作/休眠);
64 return HAL_OK;
65 }
66 else
67 {
68 return HAL_ERROR;
69 }
70}
71
73{
75}
76
78{
80}
81
83{
85 return (int_src & interrupt);
86}
87
89{
91}
uint8_t ADXL345_ReadByte(uint8_t addr)
Definition: adxl345.c:20
void ADXL345_SetInterrupts(uint8_t interrupts)
Definition: adxl345.c:72
uint16_t ADXL345_ReadInt(uint8_t addr)
Definition: adxl345.c:30
void ADXL345_EnableTapDetectOnAxes(uint8_t axes)
Definition: adxl345.c:88
HAL_StatusTypeDef ADXL345_Init(ADXL345_DataRate_t dataRate, ADXL345_SPI_Wire_t spiWire, ADXL345_IntActive_t intLevel, ADXL345_DataResolve_t resolve, ADXL345_DataAlignment_t alignment, ADXL345_G_Range_t range)
Definition: adxl345.c:50
void ADXL345_RemapInterrupts(uint8_t interrupts)
Definition: adxl345.c:77
uint8_t xbuf[3]
Definition: adxl345.c:18
void ADXL345_WriteByte(uint8_t addr, uint8_t dat)
Definition: adxl345.c:41
uint8_t ADXL345_IsInterrupt(uint8_t interrupt)
Definition: adxl345.c:82
#define ADXL345_REG_TAP_AXES
Definition: adxl345.h:44
#define ADXL345_REG_DEVID
Definition: adxl345.h:30
#define ADXL345_CS
Definition: adxl345.h:20
ADXL345_DataRate_t
Used with register 0x2C (ADXL345_REG_BW_RATE) to set bandwidth.
Definition: adxl345.h:82
#define ADXL345_REG_BW_RATE
Definition: adxl345.h:46
ADXL345_DataResolve_t
Used with register ADXL345_REG_DATA_FORMAT to set resolution mode.
Definition: adxl345.h:129
#define ADXL345_REG_DATA_FORMAT
Definition: adxl345.h:51
#define ADXL345_REG_INT_MAP
Definition: adxl345.h:49
ADXL345_G_Range_t
Used with register ADXL345_REG_DATA_FORMAT to set g range.
Definition: adxl345.h:145
#define ADXL345_REG_INT_SOURCE
Definition: adxl345.h:50
#define ADXL345_DEVICE_ID
Definition: adxl345.h:28
#define ADXL345_REG_POWER_CTL
Definition: adxl345.h:47
ADXL345_DataAlignment_t
Used with register ADXL345_REG_DATA_FORMAT to set data alignment.
Definition: adxl345.h:137
ADXL345_SPI_Wire_t
Used with register ADXL345_REG_DATA_FORMAT to set SPI wires.
Definition: adxl345.h:113
ADXL345_IntActive_t
Used with register ADXL345_REG_DATA_FORMAT to set interrupt active level.
Definition: adxl345.h:121
#define ADXL345_REG_INT_ENABLE
Definition: adxl345.h:48
__CODE int8_t dat[20]
void SPI_TxRxBytes(uint8_t *pBuf, uint8_t len)
Definition: fw_spi.c:28
unsigned short uint16_t
Definition: fw_types.h:19
HAL_StatusTypeDef
Definition: fw_types.h:75
@ HAL_ERROR
Definition: fw_types.h:77
@ HAL_OK
Definition: fw_types.h:76
unsigned char uint8_t
Definition: fw_types.h:18
uint8_t addr[8]
Definition: main.c:28