Skip to content

Commit 4a0c3bb

Browse files
committed
Added SHA204 check routine to testmode
1 parent 5b9c973 commit 4a0c3bb

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

libraries/MySensors/examples/MysensorMicro/MysensorMicro.ino

+46-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <SPI.h>
1313
#include <SPIFlash.h>
1414
#include <EEPROM.h>
15-
//#include <sha204_library.h>
16-
15+
#include <sha204_lib_return_codes.h>
16+
#include <sha204_library.h>
1717

1818
// Define a static node address, remove if you want auto address assignment
1919
//#define NODE_ADDRESS 3
@@ -28,6 +28,10 @@
2828
#define LED_PIN A2
2929
#define ATSHA204_PIN 17 // A3
3030

31+
const int sha204Pin = ATSHA204_PIN;
32+
atsha204Class sha204(sha204Pin);
33+
34+
3135
#define MEASURE_INTERVAL 60000
3236

3337
// 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)
194198
// Verify all peripherals, and signal via the LED if any problems.
195199
void testMode()
196200
{
201+
uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
202+
uint8_t ret_code;
197203
byte tests = 0;
198204

199205
Serial.println(F("Testing peripherals!"));
200206
Serial.print(F("-> SI7021 : "));
201-
delay(500);
207+
delay(100);
202208

203209
if (humiditySensor.begin())
204210
{
@@ -209,10 +215,10 @@ void testMode()
209215
{
210216
Serial.println(F("failed!"));
211217
}
212-
delay(500);
218+
delay(100);
213219

214220
Serial.print(F("-> Flash : "));
215-
delay(500);
221+
delay(100);
216222
if (flash.initialize())
217223
{
218224
Serial.println(F("ok!"));
@@ -222,10 +228,43 @@ delay(500);
222228
{
223229
Serial.println(F("failed!"));
224230
}
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+
226265
Serial.println(F("Test finished"));
227266

228-
if (tests == 2)
267+
if (tests == 3)
229268
{
230269
Serial.println(F("Selftest ok!"));
231270
while (1) // Blink OK pattern!

0 commit comments

Comments
 (0)