void DS18B20_Controller::completeSensorReadout() { // initialise OK sensors to state NOK and leave other states untouched: for(uint8_t i=0; i<numSensors; i++) { if(sensors[i]->sensorStatus == DS18B20_SENSOR_OK) { sensors[i]->sensorStatus = DS18B20_SENSOR_NOK; } sensors[i]->currentTemp = ACF_UNDEFINED_TEMPERATURE; } uint8_t addr[DS18B20_SENSOR_ID_BYTES]; while(oneWire->search(addr)) { if (OneWire::crc8(addr, DS18B20_SENSOR_ID_BYTES-1) != addr[DS18B20_SENSOR_ID_BYTES-1]) { continue; } uint8_t data[DS18B20_SENSOR_READOUT_BYTES]; if (! readSensorScratchpad(addr, data)) { continue; } DS18B20_Sensor *sensor = getSensor(addr); if (sensor != NULL) { DS18B20_Readout readout = getCelcius(data); #ifdef DEBUG_DS18B20 Serial.print(F("DEBUG_DS18B20: Sensor ")); Serial.print(sensor->label); #endif // only set temperature and state for NOK sensors and AUTO_ASSIGNED sensors (leave others untouched): if (sensor->sensorStatus == DS18B20_SENSOR_ID_AUTO_ASSIGNED) { sensor->currentTemp = readout.celcius; #ifdef DEBUG_DS18B20 char buf[MAX_DS18B20_SENSOR_ID_STR_LEN]; Serial.print(F(": ID AUTO ASSIGNED, ")); Serial.println(formatTemperature(readout.celcius, buf)); #endif } else if (sensor->sensorStatus == DS18B20_SENSOR_NOK) { // Ensure temperature is plausible: if((sensor->rangeMin == ACF_UNDEFINED_TEMPERATURE || readout.celcius >= sensor->rangeMin) && (sensor->rangeMax == ACF_UNDEFINED_TEMPERATURE || readout.celcius <= sensor->rangeMax)) { sensor->sensorStatus = DS18B20_SENSOR_OK; sensor->currentTemp = readout.celcius; #ifdef DEBUG_DS18B20 char buf[MAX_DS18B20_SENSOR_ID_STR_LEN]; Serial.print(F(": OK, ")); Serial.println(formatTemperature(readout.celcius, buf)); #endif } else { #ifdef DEBUG_DS18B20 Serial.println(F(": NOK")); #endif } } } } oneWire->reset_search(); }
int main() { int farh; printf(" °F | °C\n"); printf("---------------\n"); for(farh = MINIMO; farh <= MAXIMO; farh=farh + INCREMENTO) printf("%3d | %6.1f\n", farh, getCelcius(farh)); }
void sensorsTemperatureClass::loop() { sensorState = digitalRead(sensorStatePin); if( sensorState == HIGH ) { rawAnalog = analogRead(sensorPin); } else { rawAnalog = -1; } //print and limit ints to 3 chars sprintf(lcdRows[0], "--TEMP F:%03d--", ((int) getFahrenheit()) % 1000); sprintf(lcdRows[1], "---K:%03d C:%03d--", ((int) getKelvin()) % 1000, ((int) getCelcius()) % 1000); delay(100); }
double sensorsTemperatureClass::getFahrenheit() { return ( getCelcius() * 9.0 / 5.0 ) + 32.0; }
/********************************************************************** *********** Main Program *********************** *********************************************************************** Aim : main program NOTE : **********************************************************************/ int main (void) { SystemCoreClockUpdate(); // SysTick_Config(10000); //turn SysTick timer on SysTick_Config(SystemCoreClock/1600); // 1ms SysTicks Delay(100); //wait for system stabilization SIM->SCGC5 |= SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTB_MASK; //Port-D-B clock ON SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK; Delay(0x500); //delay LED_Init(); //Initialize the LEDs spi_init(); // SPI-1 init Delay(0x100); //delay hede=PTD->PDIR; TI_Init(); // TI_HW_Reset(); // Delay(0x3000); //delay for logic analyzer hede=PTD->PDIR; // SpiStart(); // SPI_Send(0x10); // SpiStop(); // test[0]=TI_ReadByte(0x0F); // test[1]=TI_ReadByte(0x0F); // test[2]=TI_ReadByte(0x0F); // test[3]=TI_ReadByte(0x0F); // test[4]=TI_ReadByte(0x0F); // // TI_WriteByte(CC112X_IOCFG3,0x87); // test[5]=TI_ReadByte(CC112X_IOCFG3); // TI_Command(CC112X_SRES); //sofware reset // // test[6]=TI_ReadByte(CC112X_IOCFG3); // TI_WriteByte(CC112X_IOCFG3,0x87); // test[7]=TI_ReadByte(CC112X_IOCFG3); // TI_Write_brst(CC112X_BURST_TXFIFO,toto,20); Delay(100); TI_Read_brst(CC112X_RSSI1,got,1); //Delay(100); //TI_Command(CC112X_SRES); //sofware reset setRegisters(); getReg_Test(); // TI_WriteByte(CC112X_DCFILT_CFG,0x40); // TI_WriteByte(CC112X_IOCFG2, 0x06); // TI_WriteByte(CC112X_IOCFG1, 0xB0); // TI_WriteByte(CC112X_IOCFG0, 0x40); test[0] = getCelcius(); //Read temp sensor TEST // Delay(0x2000); while(1) { // Turn on leds 1 by 1 YELLOW_ON; Delay(1000); GREEN_ON; Delay(1000); RED_ON; Delay(1000); //Turn off leds YELLOW_OFF; GREEN_OFF; RED_OFF; // SpiStart(); // hede=PTD->PDIR; // DelayUs(0x1000); // SPI_Send(0x10); // x=SPI_Send(0x00); // x=SPI_Send(0x00); // SpiStop(); // Delay(0x50); // SpiStart(); // SPI_Send(0x10); // x=SPI_Send(0x00); // SpiStop(); // hede=PTD->PDIR; // // SpiStop(); //// YELLOW_ON; Delay(1000); GREEN_ON; Delay(1000); RED_ON; Delay(1000); //// TI_WriteByte(CC112X_IOCFG3,0x87); //// test[2]=TI_ReadByte(CC112X_IOCFG3); //// YELLOW_OFF; GREEN_OFF; RED_OFF; // // PTD->PCOR |= (1UL<<4); // CS=0, SPI start // // hede=PTD->PDIR; //// test[0]=SPI_Send(0x10); // while((PTD->PDIR & 0x80)!= 0); //Wait for CHIP_RDYn signal // // SPI_Send(0x8F); //send the adress and get the status byte // test[2]= SPI_Send(0x00); //read the adress //// test[1]=SPI_Send(0x00); //// test[2]=SPI_Send(0x10); //// test[3]=SPI_Send(0x00); //// SPI_Send(0x10); // // PTD->PSOR |= (1UL<<4); // CS=0, SPI stop } }