Skip to content

Commit 239a28a

Browse files
committed
Minor changes to SPI example
1 parent 5fc1710 commit 239a28a

File tree

6 files changed

+133
-130
lines changed

6 files changed

+133
-130
lines changed

.github/workflows/compile-sketch.yml

+112-112
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,118 @@
11
name: Compile Sketch
22

33
on:
4-
# - push
5-
pull_request:
4+
- push
5+
#pull_request:
66

77
# Allows you to run this workflow manually from the Actions tab
8-
workflow_dispatch:
9-
10-
jobs:
11-
compile-sketch:
12-
runs-on: ubuntu-latest
13-
14-
strategy:
15-
fail-fast: false
16-
17-
matrix:
18-
board:
19-
# Uno
20-
# https://github.com/arduino/ArduinoCore-avr/blob/master/boards.txt
21-
- fqbn: arduino:avr:uno
22-
platforms: |
23-
- name: arduino:avr
24-
source-url: https://downloads.arduino.cc/packages/package_index.json
25-
26-
# ESP32
27-
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
28-
- fqbn: esp32:esp32:esp32
29-
platforms: |
30-
- name: esp32:esp32
31-
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
32-
33-
# ESP32-S2
34-
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
35-
- fqbn: esp32:esp32:esp32s2
36-
platforms: |
37-
- name: esp32:esp32
38-
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
39-
40-
# ESP32-C3
41-
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
42-
- fqbn: esp32:esp32:esp32c3
43-
platforms: |
44-
- name: esp32:esp32
45-
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
46-
47-
# Artemis / Apollo3
48-
# https://github.com/sparkfun/Arduino_Apollo3/blob/main/boards.txt
49-
- fqbn: SparkFun:apollo3:sfe_artemis_atp
50-
platforms: |
51-
- name: SparkFun:apollo3
52-
source-url: https://raw.githubusercontent.com/sparkfun/Arduino_Apollo3/master/package_sparkfun_apollo3_index.json
53-
54-
# ESP8266
55-
# https://github.com/esp8266/Arduino/blob/master/boards.txt
56-
- fqbn: esp8266:esp8266:thingdev
57-
platforms: |
58-
- name: esp8266:esp8266
59-
source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
60-
61-
# SAMD
62-
# https://github.com/arduino/ArduinoCore-samd/blob/master/boards.txt
63-
#- fqbn: arduino:samd:mkr1000
64-
# platforms: |
65-
# - name: arduino:samd
66-
# # source-url: https://downloads.arduino.cc/packages/package_index.json
67-
68-
# SAMD
69-
# https://github.com/arduino/ArduinoCore-samd/blob/master/boards.txt
70-
- fqbn: arduino:samd:nano_33_iot
71-
platforms: |
72-
- name: arduino:samd
73-
# source-url: https://downloads.arduino.cc/packages/package_index.json
74-
75-
# Nano BLE 33 / nRF52840
76-
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
77-
- fqbn: arduino:mbed:nano33ble
78-
platforms: |
79-
- name: arduino:mbed
80-
# source-url: https://downloads.arduino.cc/packages/package_index.json
81-
82-
# RP2040
83-
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
84-
- fqbn: rp2040:rp2040:sparkfun_promicrorp2040
85-
platforms: |
86-
- name: rp2040:rp2040
87-
source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
88-
89-
# STM32
90-
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
91-
- fqbn: STMicroelectronics:stm32:GenF4
92-
platforms: |
93-
- name: STMicroelectronics:stm32
94-
source-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
95-
96-
steps:
97-
- name: Checkout
98-
uses: actions/checkout@v2
99-
100-
- name: Branch name
101-
run: echo running on branch ${GITHUB_REF##*/}
102-
103-
- name: Compile Sketch
104-
uses: arduino/compile-sketches@v1
105-
with:
106-
platforms: ${{ matrix.board.platforms }}
107-
fqbn: ${{ matrix.board.fqbn }}
108-
libraries: |
109-
- source-path: ./
110-
sketch-paths: |
111-
- examples/example3_buffer
112-
enable-warnings-report: true
113-
enable-deltas-report: true
114-
# verbose: true
115-
116-
# outputs:
117-
# report-artifact-name: ${{ steps.report-artifact-name.outputs.report-artifact-name }}
8+
#workflow_dispatch:
9+
10+
jobs:
11+
compile-sketch:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
17+
matrix:
18+
board:
19+
# Uno
20+
# https://github.com/arduino/ArduinoCore-avr/blob/master/boards.txt
21+
- fqbn: arduino:avr:uno
22+
platforms: |
23+
- name: arduino:avr
24+
source-url: https://downloads.arduino.cc/packages/package_index.json
25+
26+
# ESP32
27+
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
28+
- fqbn: esp32:esp32:esp32
29+
platforms: |
30+
- name: esp32:esp32
31+
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
32+
33+
# ESP32-S2
34+
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
35+
- fqbn: esp32:esp32:esp32s2
36+
platforms: |
37+
- name: esp32:esp32
38+
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
39+
40+
# ESP32-C3
41+
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
42+
- fqbn: esp32:esp32:esp32c3
43+
platforms: |
44+
- name: esp32:esp32
45+
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
46+
47+
# Artemis / Apollo3
48+
# https://github.com/sparkfun/Arduino_Apollo3/blob/main/boards.txt
49+
- fqbn: SparkFun:apollo3:sfe_artemis_atp
50+
platforms: |
51+
- name: SparkFun:apollo3
52+
source-url: https://raw.githubusercontent.com/sparkfun/Arduino_Apollo3/master/package_sparkfun_apollo3_index.json
53+
54+
# ESP8266
55+
# https://github.com/esp8266/Arduino/blob/master/boards.txt
56+
- fqbn: esp8266:esp8266:thingdev
57+
platforms: |
58+
- name: esp8266:esp8266
59+
source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
60+
61+
# SAMD
62+
# https://github.com/arduino/ArduinoCore-samd/blob/master/boards.txt
63+
#- fqbn: arduino:samd:mkr1000
64+
# platforms: |
65+
# - name: arduino:samd
66+
# # source-url: https://downloads.arduino.cc/packages/package_index.json
67+
68+
# SAMD
69+
# https://github.com/arduino/ArduinoCore-samd/blob/master/boards.txt
70+
- fqbn: arduino:samd:nano_33_iot
71+
platforms: |
72+
- name: arduino:samd
73+
# source-url: https://downloads.arduino.cc/packages/package_index.json
74+
75+
# Nano BLE 33 / nRF52840
76+
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
77+
- fqbn: arduino:mbed:nano33ble
78+
platforms: |
79+
- name: arduino:mbed
80+
# source-url: https://downloads.arduino.cc/packages/package_index.json
81+
82+
# RP2040
83+
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
84+
- fqbn: rp2040:rp2040:sparkfun_promicrorp2040
85+
platforms: |
86+
- name: rp2040:rp2040
87+
source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
88+
89+
# STM32
90+
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
91+
- fqbn: STMicroelectronics:stm32:GenF4
92+
platforms: |
93+
- name: STMicroelectronics:stm32
94+
source-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
95+
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v2
99+
100+
- name: Branch name
101+
run: echo running on branch ${GITHUB_REF##*/}
102+
103+
- name: Compile Sketch
104+
uses: arduino/compile-sketches@v1
105+
with:
106+
platforms: ${{ matrix.board.platforms }}
107+
fqbn: ${{ matrix.board.fqbn }}
108+
libraries: |
109+
- source-path: ./
110+
sketch-paths: |
111+
- examples/example3_buffer
112+
enable-warnings-report: true
113+
enable-deltas-report: true
114+
# verbose: true
115+
116+
# outputs:
117+
# report-artifact-name: ${{ steps.report-artifact-name.outputs.report-artifact-name }}
118118

examples/example5_spi/example5_spi.ino

+11-12
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,32 @@
2323
#include <SPI.h>
2424
#include <SparkFun_KX13X.h> // Click here to get the library: http://librarymanager/All#SparkFun_KX13X
2525

26-
SparkFun_KX132_SPI kxAccel;
27-
// SparkFun_KX134_SPI kxAccel; // For the KX134, uncomment this and comment line above
26+
//SparkFun_KX132_SPI kxAccel;
27+
SparkFun_KX134_SPI kxAccel; // For the KX134, uncomment this and comment line above
2828

2929
outputData myData; // Struct for the accelerometer's data
30-
byte chipSelect = 1; // Change to fit your project.
30+
const int chipSelect = A2; // Change to fit your project.
3131

3232
void setup()
3333
{
3434

35+
Serial.begin(115200);
3536
// Get the chip select pin ready.
3637
pinMode(chipSelect, OUTPUT);
3738
digitalWrite(chipSelect, HIGH);
3839

3940
SPI.begin();
4041

41-
Serial.begin(115200);
42-
Serial.println("Welcome.");
43-
4442
// Wait for the Serial monitor to be opened.
4543
while (!Serial)
4644
delay(50);
4745

48-
if (!kxAccel.begin(chipSelect))
46+
while (!kxAccel.begin(chipSelect))
4947
{
48+
Serial.print("Unique ID: 0x");
49+
Serial.println(kxAccel.getUniqueID(), HEX);
5050
Serial.println("Could not communicate with the the KX13X. Freezing.");
51-
while (1)
52-
;
51+
delay(1000);
5352
}
5453

5554
Serial.println("Ready.");
@@ -84,11 +83,11 @@ void loop()
8483
{
8584
kxAccel.getAccelData(&myData);
8685
Serial.print("X: ");
87-
Serial.print(myData.xData, 4);
86+
Serial.print(myData.xData, 3);
8887
Serial.print(" Y: ");
89-
Serial.print(myData.yData, 4);
88+
Serial.print(myData.yData, 3);
9089
Serial.print(" Z: ");
91-
Serial.print(myData.zData, 4);
90+
Serial.print(myData.zData, 3);
9291
Serial.println();
9392
}
9493
delay(20); // Delay should be 1/ODR (Output Data Rate), default is 1/50ODR

src/SparkFun_KX13X.h

+1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ class SparkFun_KX134_SPI : public QwDevKX134
258258

259259
// Initialize the system - return results
260260
return this->QwDevKX134::init();
261+
261262
}
262263

263264
bool begin(SPIClass &spiPort, SPISettings kxSettings, uint8_t cs)

src/SparkFun_KX13X_regs.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@
4141

4242
// This file holds the bit fields for the KX132/KX134 registers.
4343

44-
#define SFE_KX13X_MAN_ID \
45-
0x00 // Retuns "KION" in ASCII
46-
//
44+
#define SFE_KX13X_MAN_ID 0x00 // Retuns "KION" in ASCII
45+
4746
typedef struct
4847
{
4948
uint8_t man_id : 8;

src/SparkFun_Qwiic_KX13X.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool QwDevKX13X::initialize(uint8_t settings)
6262
}
6363
}
6464

65-
if (settings == INT_SETTINGS)
65+
else if (settings == INT_SETTINGS)
6666
{
6767
enablePhysInterrupt();
6868
routeHardwareInterrupt(0x10);
@@ -74,7 +74,7 @@ bool QwDevKX13X::initialize(uint8_t settings)
7474
}
7575
}
7676

77-
if (settings == BUFFER_SETTINGS)
77+
else if (settings == BUFFER_SETTINGS)
7878
{
7979
enablePhysInterrupt();
8080
routeHardwareInterrupt(0x40); // Buffer full interrupt
@@ -87,6 +87,10 @@ bool QwDevKX13X::initialize(uint8_t settings)
8787
_range = cntl1.bits.gsel; // Record the G-range
8888
}
8989
}
90+
else
91+
{
92+
return false;
93+
}
9094

9195
if (retVal != 0)
9296
return false;

src/sfe_bus.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,4 @@ namespace sfe_KX13X
362362
return 0;
363363
}
364364

365-
}
365+
}

0 commit comments

Comments
 (0)