PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Devices
Sensor
Accelerometer 3-Axis LIS3DH
LIS3DH Test SPI 4-Wire Init.c
1
/*
2
LIS3DH Test SPI 4-Wire Init.c
3
4
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
5
6
I/O Pins connections:
7
8
P8 -> CLK (SCK)
9
P7 -> DATA (SDI)
10
P6 <- DATA (SDO)
11
P5 -> /ENABLE (CS)
12
13
Instructions:
14
15
Connect LIS3DH module to Propeller using the pins shown above
16
Also connect 3.3V and GND to the LIS3DH module
17
Upload this code to the Propeller
18
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
19
*/
20
21
#include "
simpletools.h
"
// Include simpletools header
22
#include "
lis3dh.h
"
// Include lis3dh header
23
24
lis3dh
*LIS3DH;
25
26
int
main
()
// Main function
27
{
28
29
pause
(1000);
// Start-up pause for debug terminal
30
term_cmd
(
CLS
);
31
term_cmd
(
HOME
);
32
33
print
(
"Parallax LIS3DH 3 Axis Accelerometer module with ADC %c \r"
,
CLREOL
);
34
print
(
"Test SPI 4-Wire Init %c \r\r"
,
CLREOL
);
35
36
37
LIS3DH =
lis3dh_init4wire
(8, 7, 6, 5);
// Initialize sensor with pins SCK, SDI, SDO, CS
38
39
40
print
(
"WhoAmI : %d (%s) %c \r\r"
,
// Read WhoAmI register to verify connection
41
lis3dh_getWhoAmI
(LIS3DH),
42
(
lis3dh_getWhoAmI
(LIS3DH) == LIS3DH_WHO_AM_I_REPLY)?
"OK"
:
"ERROR"
,
43
CLREOL
);
44
45
46
lis3dh_shutdown
(LIS3DH);
// When finished, optionally shutdown sensor to clear setting registers, buffers and set low-power-mode (disable sensor)
47
48
}
49
50
51
CLS
#define CLS
CLS character (16) clears SimpleIDE's screen, erasing all characters and placing the cursor in the to...
Definition:
simpletools.h:363
HOME
#define HOME
HOME character (1) sends SimpleIDE Terminal's cursor to top-left "home" position.
Definition:
simpletools.h:233
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
lis3dh_init4wire
lis3dh_t * lis3dh_init4wire(int pinSCK, int pinSDI, int pinSDO, int pinCS)
Initialize the sensor with typical configuration for reading axis and adc. Uses 4-Wire SPI mode.
Definition:
init.c:29
lis3dh_shutdown
void lis3dh_shutdown(lis3dh_t *device)
Shutdown the sensor, set configuration defaults with sensor disabled and clear buffers.
Definition:
shutdown.c:21
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
lis3dh.h
Simplifies reading Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
term_cmd
void term_cmd(int termConst,...)
Send a command to SimpleIDE Terminal. Examples of commands include HOME, CLS, BKSP,...
Definition:
term_cmd.c:44
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
lis3dh_getWhoAmI
int lis3dh_getWhoAmI(lis3dh_t *device)
Reads the sensor identification register (WhoAmI).
Definition:
getWhoAmI.c:21
lis3dh_st
Definition:
lis3dh.h:122
CLREOL
#define CLREOL
CLREOL character (11) erases all SimpleIDE Terminal characters to the right of the cursor.
Definition:
simpletools.h:323
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17