Пример #1
0
void readTemp()
{
  PORTC &= 0b11111000;; //turns off display because interrupts are disabled during DS18b20 measurements
  volatile int16_t decicelsius;
  DS18X20_start_meas( DS18X20_POWER_EXTERN, NULL );
  _delay_ms( DS18B20_TCONV_12BIT );
  DS18X20_read_decicelsius_single( gSensorIDs[0][0], &decicelsius );
  display[0] = decicelsius / 100; 
  display[1] = (decicelsius - (display[0] * 100))/ 10;
  display[2] = decicelsius % 10;
}
Пример #2
0
void hw_read_tick(Context * ctx)
{

	/* DS */
	if (DS18X20_conversion_in_progress() == DS18X20_CONVERSION_DONE) {
		if (DS18X20_read_decicelsius_single(DS18B20_FAMILY_CODE, &ctx->t1) == DS18X20_OK) {
			ctx->temp_status = DS_OK;
		} else {
			ctx->temp_status = DS_READ_ERROR;
		}
		if (DS18X20_start_meas(DS18X20_POWER_EXTERN, NULL) != DS18X20_OK) {
			ctx->temp_status = DS_MEAS_ERROR;
		}
	}
}
Пример #3
0
int main( void )
{
    uint8_t nSensors, i;
    int16_t decicelsius;
    uint8_t error;

    uart_init((UART_BAUD_SELECT((BAUD),F_CPU)));

#ifndef OW_ONE_BUS
    ow_set_bus(&PINA,&PORTA,&DDRA,PA6);
#endif

    sei();

    uart_puts_P( NEWLINESTR "DS18X20 1-Wire-Reader Demo by Martin Thomas" NEWLINESTR );
    uart_puts_P(            "-------------------------------------------" );

    nSensors = search_sensors();
    uart_put_int( (int)nSensors );
    uart_puts_P( " DS18X20 Sensor(s) available:" NEWLINESTR );

#if DS18X20_VERBOSE
    for (i = 0; i < nSensors; i++ ) {
        uart_puts_P("# in Bus :");
        uart_put_int( (int)i + 1);
        uart_puts_P(" : ");
        DS18X20_show_id_uart( &gSensorIDs[i][0], OW_ROMCODE_SIZE );
        uart_puts_P( NEWLINESTR );
    }
#endif

    for ( i = 0; i < nSensors; i++ ) {
        uart_puts_P( "Sensor# " );
        uart_put_int( (int)i+1 );
        uart_puts_P( " is a " );
        if ( gSensorIDs[i][0] == DS18S20_FAMILY_CODE ) {
            uart_puts_P( "DS18S20/DS1820" );
        } else if ( gSensorIDs[i][0] == DS1822_FAMILY_CODE ) {
            uart_puts_P( "DS1822" );
        }
        else {
            uart_puts_P( "DS18B20" );
        }
        uart_puts_P( " which is " );
        if ( DS18X20_get_power_status( &gSensorIDs[i][0] ) == DS18X20_POWER_PARASITE ) {
            uart_puts_P( "parasite" );
        } else {
            uart_puts_P( "externally" );
        }
        uart_puts_P( " powered" NEWLINESTR );
    }

#if DS18X20_EEPROMSUPPORT
    if ( nSensors > 0 ) {
        eeprom_test();
    }
#endif

    if ( nSensors == 1 ) {
        uart_puts_P( NEWLINESTR "There is only one sensor "
                     "-> Demo of \"DS18X20_read_decicelsius_single\":" NEWLINESTR );
        i = gSensorIDs[0][0]; // family-code for conversion-routine
        DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
        _delay_ms( DS18B20_TCONV_12BIT );
        DS18X20_read_decicelsius_single( i, &decicelsius );
        uart_put_temp( decicelsius );
        uart_puts_P( NEWLINESTR );
    }


    for(;;) {   // main loop

        error = 0;

        if ( nSensors == 0 ) {
            error++;
        }

        uart_puts_P( NEWLINESTR "Convert_T and Read Sensor by Sensor (reverse order)" NEWLINESTR );
        for ( i = nSensors; i > 0; i-- ) {
            if ( DS18X20_start_meas( DS18X20_POWER_PARASITE,
                                     &gSensorIDs[i-1][0] ) == DS18X20_OK ) {
                _delay_ms( DS18B20_TCONV_12BIT );
                uart_puts_P( "Sensor# " );
                uart_put_int( (int) i );
                uart_puts_P(" = ");
                if ( DS18X20_read_decicelsius( &gSensorIDs[i-1][0], &decicelsius)
                        == DS18X20_OK ) {
                    uart_put_temp( decicelsius );
                } else {
                    uart_puts_P( "CRC Error (lost connection?)" );
                    error++;
                }
                uart_puts_P( NEWLINESTR );
            }
            else {
                uart_puts_P( "Start meas. failed (short circuit?)" );
                error++;
            }
        }

        uart_puts_P( NEWLINESTR "Convert_T for all Sensors and Read Sensor by Sensor" NEWLINESTR );
        if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL )
                == DS18X20_OK) {
            _delay_ms( DS18B20_TCONV_12BIT );
            for ( i = 0; i < nSensors; i++ ) {
                uart_puts_P( "Sensor# " );
                uart_put_int( (int)i + 1 );
                uart_puts_P(" = ");
                if ( DS18X20_read_decicelsius( &gSensorIDs[i][0], &decicelsius )
                        == DS18X20_OK ) {
                    uart_put_temp( decicelsius );
                }
                else {
                    uart_puts_P( "CRC Error (lost connection?)" );
                    error++;
                }
                uart_puts_P( NEWLINESTR );
            }
#if DS18X20_MAX_RESOLUTION
            int32_t temp_eminus4;
            for ( i = 0; i < nSensors; i++ ) {
                uart_puts_P( "Sensor# " );
                uart_put_int( i+1 );
                uart_puts_P(" = ");
                if ( DS18X20_read_maxres( &gSensorIDs[i][0], &temp_eminus4 )
                        == DS18X20_OK ) {
                    uart_put_temp_maxres( temp_eminus4 );
                }
                else {
                    uart_puts_P( "CRC Error (lost connection?)" );


                    error++;
                }
                uart_puts_P( NEWLINESTR );
            }
#endif
        }
        else {
            uart_puts_P( "Start meas. failed (short circuit?)" );
            error++;
        }


#if DS18X20_VERBOSE
        // all devices:
        uart_puts_P( NEWLINESTR "Verbose output" NEWLINESTR );
        DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
        _delay_ms( DS18B20_TCONV_12BIT );
        DS18X20_read_meas_all_verbose();
#endif

        if ( error ) {
            uart_puts_P( "*** problems - rescanning bus ..." );
            nSensors = search_sensors();
            uart_put_int( (int) nSensors );
            uart_puts_P( " DS18X20 Sensor(s) available" NEWLINESTR );
            error = 0;
        }

        _delay_ms(3000);
    }
}