12
12
#include < SPI.h>
13
13
#include < SPIFlash.h>
14
14
#include < EEPROM.h>
15
- // #include <sha204_library .h>
16
-
15
+ #include < sha204_lib_return_codes .h>
16
+ # include < sha204_library.h >
17
17
18
18
// Define a static node address, remove if you want auto address assignment
19
19
// #define NODE_ADDRESS 3
28
28
#define LED_PIN A2
29
29
#define ATSHA204_PIN 17 // A3
30
30
31
+ const int sha204Pin = ATSHA204_PIN;
32
+ atsha204Class sha204 (sha204Pin);
33
+
34
+
31
35
#define MEASURE_INTERVAL 60000
32
36
33
37
// FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller
@@ -194,11 +198,13 @@ void switchClock(unsigned char clk)
194
198
// Verify all peripherals, and signal via the LED if any problems.
195
199
void testMode ()
196
200
{
201
+ uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
202
+ uint8_t ret_code;
197
203
byte tests = 0 ;
198
204
199
205
Serial.println (F (" Testing peripherals!" ));
200
206
Serial.print (F (" -> SI7021 : " ));
201
- delay (500 );
207
+ delay (100 );
202
208
203
209
if (humiditySensor.begin ())
204
210
{
@@ -209,10 +215,10 @@ void testMode()
209
215
{
210
216
Serial.println (F (" failed!" ));
211
217
}
212
- delay (500 );
218
+ delay (100 );
213
219
214
220
Serial.print (F (" -> Flash : " ));
215
- delay (500 );
221
+ delay (100 );
216
222
if (flash.initialize ())
217
223
{
218
224
Serial.println (F (" ok!" ));
@@ -222,10 +228,43 @@ delay(500);
222
228
{
223
229
Serial.println (F (" failed!" ));
224
230
}
225
- delay (500 );
231
+ delay (100 );
232
+
233
+ Serial.println (F (" -> SHA204 : " ));
234
+ ret_code = sha204.sha204c_wakeup (rx_buffer);
235
+ if (ret_code != SHA204_SUCCESS)
236
+ {
237
+ Serial.print (F (" Failed to wake device. Response: " )); Serial.println (ret_code, HEX);
238
+ }
239
+
240
+ if (ret_code == SHA204_SUCCESS)
241
+ {
242
+ ret_code = sha204.getSerialNumber (rx_buffer);
243
+ if (ret_code != SHA204_SUCCESS)
244
+ {
245
+ Serial.print (F (" Failed to obtain device serial number. Response: " )); Serial.println (ret_code, HEX);
246
+ }
247
+ else
248
+ {
249
+ Serial.print (F (" Device serial: " ));
250
+ for (int i=0 ; i<9 ; i++)
251
+ {
252
+ if (rx_buffer[i] < 0x10 )
253
+ {
254
+ Serial.print (' 0' ); // Because Serial.print does not 0-pad HEX
255
+ }
256
+ Serial.print (rx_buffer[i], HEX);
257
+ }
258
+ Serial.println ();
259
+ tests ++;
260
+ }
261
+
262
+ }
263
+
264
+
226
265
Serial.println (F (" Test finished" ));
227
266
228
- if (tests == 2 )
267
+ if (tests == 3 )
229
268
{
230
269
Serial.println (F (" Selftest ok!" ));
231
270
while (1 ) // Blink OK pattern!
0 commit comments