|
@@ -150,67 +150,65 @@ void onewireTest(void) {
|
|
|
for (i=0; i<3; i++)
|
|
|
temperature[i] = -666;
|
|
|
|
|
|
- while (true) {
|
|
|
- if (true == onewireReset(&OWD1)){
|
|
|
-
|
|
|
- memset(rombuf, 0x55, sizeof(rombuf));
|
|
|
- search_led_on();
|
|
|
- devices_on_bus = onewireSearchRom(&OWD1, rombuf, 3);
|
|
|
- search_led_off();
|
|
|
- osalDbgCheck(devices_on_bus <= 3);
|
|
|
- osalDbgCheck(devices_on_bus > 0);
|
|
|
-
|
|
|
- if (1 == devices_on_bus){
|
|
|
- /* test read rom command */
|
|
|
- presence = onewireReset(&OWD1);
|
|
|
- osalDbgCheck(true == presence);
|
|
|
- testbuf[0] = ONEWIRE_CMD_READ_ROM;
|
|
|
- onewireWrite(&OWD1, testbuf, 1, 0);
|
|
|
- onewireRead(&OWD1, testbuf, 8);
|
|
|
- osalDbgCheck(testbuf[7] == onewireCRC(testbuf, 7));
|
|
|
- osalDbgCheck(0 == memcmp(rombuf, testbuf, 8));
|
|
|
- }
|
|
|
-
|
|
|
- /* start temperature measurement on all connected devices at once */
|
|
|
+ if (true == onewireReset(&OWD1)){
|
|
|
+
|
|
|
+ memset(rombuf, 0x55, sizeof(rombuf));
|
|
|
+ search_led_on();
|
|
|
+ devices_on_bus = onewireSearchRom(&OWD1, rombuf, 3);
|
|
|
+ search_led_off();
|
|
|
+ osalDbgCheck(devices_on_bus <= 3);
|
|
|
+ osalDbgCheck(devices_on_bus > 0);
|
|
|
+
|
|
|
+ if (1 == devices_on_bus){
|
|
|
+ /* test read rom command */
|
|
|
presence = onewireReset(&OWD1);
|
|
|
osalDbgCheck(true == presence);
|
|
|
- testbuf[0] = ONEWIRE_CMD_SKIP_ROM;
|
|
|
- testbuf[1] = ONEWIRE_CMD_CONVERT_TEMP;
|
|
|
+ testbuf[0] = ONEWIRE_CMD_READ_ROM;
|
|
|
+ onewireWrite(&OWD1, testbuf, 1, 0);
|
|
|
+ onewireRead(&OWD1, testbuf, 8);
|
|
|
+ osalDbgCheck(testbuf[7] == onewireCRC(testbuf, 7));
|
|
|
+ osalDbgCheck(0 == memcmp(rombuf, testbuf, 8));
|
|
|
+ }
|
|
|
+
|
|
|
+ /* start temperature measurement on all connected devices at once */
|
|
|
+ presence = onewireReset(&OWD1);
|
|
|
+ osalDbgCheck(true == presence);
|
|
|
+ testbuf[0] = ONEWIRE_CMD_SKIP_ROM;
|
|
|
+ testbuf[1] = ONEWIRE_CMD_CONVERT_TEMP;
|
|
|
|
|
|
#if ONEWIRE_USE_STRONG_PULLUP
|
|
|
- onewireWrite(&OWD1, testbuf, 2, TIME_MS2I(750));
|
|
|
+ onewireWrite(&OWD1, testbuf, 2, TIME_MS2I(750));
|
|
|
#else
|
|
|
- onewireWrite(&OWD1, testbuf, 2, 0);
|
|
|
- /* poll bus waiting ready signal from all connected devices */
|
|
|
- testbuf[0] = 0;
|
|
|
- while (testbuf[0] == 0){
|
|
|
- osalThreadSleepMilliseconds(50);
|
|
|
- onewireRead(&OWD1, testbuf, 1);
|
|
|
- }
|
|
|
+ onewireWrite(&OWD1, testbuf, 2, 0);
|
|
|
+ /* poll bus waiting ready signal from all connected devices */
|
|
|
+ testbuf[0] = 0;
|
|
|
+ while (testbuf[0] == 0){
|
|
|
+ osalThreadSleepMilliseconds(50);
|
|
|
+ onewireRead(&OWD1, testbuf, 1);
|
|
|
+ }
|
|
|
#endif
|
|
|
|
|
|
- for (i=0; i<devices_on_bus; i++) {
|
|
|
- /* read temperature device by device from their scratchpads */
|
|
|
- presence = onewireReset(&OWD1);
|
|
|
- osalDbgCheck(true == presence);
|
|
|
-
|
|
|
- testbuf[0] = ONEWIRE_CMD_MATCH_ROM;
|
|
|
- memcpy(&testbuf[1], &rombuf[i*8], 8);
|
|
|
- testbuf[9] = ONEWIRE_CMD_READ_SCRATCHPAD;
|
|
|
- onewireWrite(&OWD1, testbuf, 10, 0);
|
|
|
-
|
|
|
- onewireRead(&OWD1, testbuf, 9);
|
|
|
- osalDbgCheck(testbuf[8] == onewireCRC(testbuf, 8));
|
|
|
- memcpy(&tmp, &testbuf, 2);
|
|
|
- temperature[i] = ((int32_t)tmp * 625) / 10;
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- devices_on_bus = 0;
|
|
|
+ for (i=0; i<devices_on_bus; i++) {
|
|
|
+ /* read temperature device by device from their scratchpads */
|
|
|
+ presence = onewireReset(&OWD1);
|
|
|
+ osalDbgCheck(true == presence);
|
|
|
+
|
|
|
+ testbuf[0] = ONEWIRE_CMD_MATCH_ROM;
|
|
|
+ memcpy(&testbuf[1], &rombuf[i*8], 8);
|
|
|
+ testbuf[9] = ONEWIRE_CMD_READ_SCRATCHPAD;
|
|
|
+ onewireWrite(&OWD1, testbuf, 10, 0);
|
|
|
+
|
|
|
+ onewireRead(&OWD1, testbuf, 9);
|
|
|
+ osalDbgCheck(testbuf[8] == onewireCRC(testbuf, 8));
|
|
|
+ memcpy(&tmp, &testbuf, 2);
|
|
|
+ temperature[i] = ((int32_t)tmp * 625) / 10;
|
|
|
}
|
|
|
- osalThreadSleep(1); /* enforce ChibiOS's stack overflow check */
|
|
|
}
|
|
|
-
|
|
|
+ else {
|
|
|
+ devices_on_bus = 0;
|
|
|
+ }
|
|
|
+ osalThreadSleep(1); /* enforce ChibiOS's stack overflow check */
|
|
|
+
|
|
|
onewireStop(&OWD1);
|
|
|
}
|
|
|
|
|
@@ -222,6 +220,6 @@ int32_t onewireGetTemperature(const size_t num) {
|
|
|
if (num > devices_on_bus || num < devices_on_bus) {
|
|
|
return -999;
|
|
|
} else {
|
|
|
- return temperature[num];
|
|
|
+ return temperature[num-1];
|
|
|
}
|
|
|
}
|