int OneWire_PerformTemperatureConversion(void) { uint8_t scratch[9]; if(resetbus()) { xferbyte(OW_SKIP_ROM); // All devices on the bus are addressed here xferbyte(OW_CONVERT_T); setpin1(); BusyWait8(94000<<3); // For 9-bit resolution for( int i = 0; i < numowdevices; i++ ) { selectdevbyidx(i); xferbyte(OW_READ_SCRATCHPAD); for(uint32_t iter=0; iter<2; iter++) { // Only read two bytes scratch[iter] = xferbyte(0xff); //printf("%02x ",scratch[iter]); } int16_t tmp = scratch[1]<<8 | scratch[0]; devreadout[i] = tmp; } } else { BusyWait8(94000<<3); // Maintain timing if no sensors are found for the time being } return numowdevices; }
static int32_t OneWire_Work(void) { static uint8_t mystate = 0; uint8_t scratch[9]; int32_t retval = 0; if (mystate == 0) { uint32_t save = VIC_DisableIRQ(); if (resetbus()) { xferbyte(OW_SKIP_ROM); // All devices on the bus are addressed here xferbyte(OW_CONVERT_T); setpin1(); //retval = TICKS_MS(94); // For 9-bit resolution retval = TICKS_MS(100); // TC interface needs max 100ms to be ready mystate++; } VIC_RestoreIRQ( save ); } else if (mystate == 1) { for (int i = 0; i < numowdevices; i++) { uint32_t save = VIC_DisableIRQ(); selectdevbyidx(i); xferbyte(OW_READ_SCRATCHPAD); for (uint32_t iter = 0; iter < 4; iter++) { // Read four bytes scratch[iter] = xferbyte(0xff); } VIC_RestoreIRQ(save); int16_t tmp = scratch[1]<<8 | scratch[0]; devreadout[i] = tmp; tmp = scratch[3]<<8 | scratch[2]; extrareadout[i] = tmp; } mystate = 0; } else { retval = -1; } return retval; }