Exemplo n.º 1
0
void show_sp_uart( uint8_t *sp, size_t n )
{
	size_t i;
	uart_puts_P( "SP:" );
	for( i = 0; i < n; i++ ) {
		if ( i == n-1 ) uart_puts_P( "CRC:" );
		uart_puthex_byte(sp[i]);
		uart_puts_P(" ");
	}
}
Exemplo n.º 2
0
void ping_me(uint8_t c) {
	asm("eor r1,r1"); // we don't know where we came from
	cli();
    DBG_OFF();DBG_ON();DBG_OFF();DBG_ON();DBG_OFF();
    DBG(c);
    DBG_ON();DBG_OFF(); DBG_ON();DBG_OFF();
#if defined(HAVE_WATCHDOG)
	wdt_reset();
#endif
#ifdef HAVE_UART_SYNC
	uart_puts_P("\nDEAD x");
	uart_puthex_byte(c);
	uart_putc('\n');
	uart_putc(' ');
#endif
	wdt_enable(0); // (almost) immediate
    do {} while(1);
}
Exemplo n.º 3
0
void DS18X20_show_id_uart( uint8_t *id, size_t n )
{
	size_t i;
	for( i = 0; i < n; i++ ) {
	    if ( i == 0 ) uart_puts_P( "FC:" );
		else if ( i == n-1 ) uart_puts_P( "CRC:" );
		if ( i == 1 ) uart_puts_P( "SN: " );
		uart_puthex_byte(id[i]);
		uart_puts_P(" ");
		if ( i == 0 ) {
			if ( id[0] == DS18S20_ID ) uart_puts_P ("(18S)");
			else if ( id[0] == DS18B20_ID ) uart_puts_P ("(18B)");
			else uart_puts_P ("( ? )");
		}
	}
	if ( crc8( id, OW_ROMCODE_SIZE) )
		uart_puts_P( " CRC FAIL " );
	else 
		uart_puts_P( " CRC O.K. " );
}
Exemplo n.º 4
0
/* verbose output rom-search follows read-scratchpad in one loop */
uint8_t DS18X20_read_meas_all_verbose( void )
{
	uint8_t id[OW_ROMCODE_SIZE], sp[DS18X20_SP_SIZE], diff;
	uint8_t i;
	uint16_t meas;
	int16_t decicelsius;
	char s[10];
	uint8_t subzero, cel, cel_frac_bits;

	for( diff = OW_SEARCH_FIRST; diff != OW_LAST_DEVICE; )
	{
		diff = ow_rom_search( diff, &id[0] );

		if( diff == OW_PRESENCE_ERR ) {
			uart_puts_P( "No Sensor found\r" );
			return OW_PRESENCE_ERR; // <--- early exit!
		}

		if( diff == OW_DATA_ERR ) {
			uart_puts_P( "Bus Error\r" );
			return OW_DATA_ERR;     // <--- early exit!
		}

		DS18X20_show_id_uart( id, OW_ROMCODE_SIZE );

		if( id[0] == DS18B20_FAMILY_CODE || id[0] == DS18S20_FAMILY_CODE ||
		    id[0] == DS1822_FAMILY_CODE ) {
			// temperature sensor

			uart_putc ('\r');

			ow_byte_wr( DS18X20_READ );           // read command

			for ( i=0 ; i< DS18X20_SP_SIZE; i++ ) {
				sp[i]=ow_byte_rd();
			}

			show_sp_uart( sp, DS18X20_SP_SIZE );

			if ( crc8( &sp[0], DS18X20_SP_SIZE ) ) {
				uart_puts_P( " CRC FAIL " );
			} else {
				uart_puts_P( " CRC O.K. " );
			}
			uart_putc ('\r');

			meas = sp[0]; // LSB Temp. from Scrachpad-Data
			meas |= (uint16_t) (sp[1] << 8); // MSB

			uart_puts_P( " T_raw=");
			uart_puthex_byte( (uint8_t)(meas >> 8) );
			uart_puthex_byte( (uint8_t)meas );
			uart_puts_P( " " );

			if( id[0] == DS18S20_FAMILY_CODE ) { // 18S20
				uart_puts_P( "S20/09" );
			}
			else if ( id[0] == DS18B20_FAMILY_CODE ||
			          id[0] == DS1822_FAMILY_CODE ) { // 18B20 or 1822
				i=sp[DS18B20_CONF_REG];
				if ( (i & DS18B20_12_BIT) == DS18B20_12_BIT ) {
					uart_puts_P( "B20/12" );
				}
				else if ( (i & DS18B20_11_BIT) == DS18B20_11_BIT ) {
					uart_puts_P( "B20/11" );
				}
				else if ( (i & DS18B20_10_BIT) == DS18B20_10_BIT ) {
					uart_puts_P( " B20/10 " );
				}
				else { // if ( (i & DS18B20_9_BIT) == DS18B20_9_BIT ) {
					uart_puts_P( "B20/09" );
				}
			}
			uart_puts_P(" ");

			DS18X20_meas_to_cel( id[0], sp, &subzero, &cel, &cel_frac_bits );
			DS18X20_uart_put_temp( subzero, cel, cel_frac_bits );

			decicelsius = DS18X20_raw_to_decicelsius( id[0], sp );
			if ( decicelsius == DS18X20_INVALID_DECICELSIUS ) {
				uart_puts_P("* INVALID *");
			} else {
				uart_puts_P(" conv: ");
				uart_put_int(decicelsius);
				uart_puts_P(" deci°C ");
				DS18X20_format_from_decicelsius( decicelsius, s, 10 );
				uart_puts_P(" fmt: ");
				uart_puts(s);
				uart_puts_P(" °C ");
			}

			uart_puts("\r");

		} // if meas-sensor

	} // loop all sensors
Exemplo n.º 5
0
/* verbose output rom-search follows read-scratchpad in one loop */
uint8_t DS18X20_read_meas_all_verbose( void )
{
	uint8_t id[OW_ROMCODE_SIZE], sp[DS18X20_SP_SIZE], diff;
	
	uint8_t i;
	uint16_t meas;
	
	uint8_t subzero, cel, cel_frac_bits;
	
	for( diff = OW_SEARCH_FIRST; diff != OW_LAST_DEVICE; )
	{
		diff = ow_rom_search( diff, &id[0] );

		if( diff == OW_PRESENCE_ERR ) {
		  uart_puts_P( "No Sensor found\r\n" );
		  return OW_PRESENCE_ERR;
		}
		
		if( diff == OW_DATA_ERR ) {
		  uart_puts_P( "Bus Error\r\n" );
		  return OW_DATA_ERR;
		}
		
		DS18X20_show_id_uart( id, OW_ROMCODE_SIZE );
		
		if( id[0] == DS18B20_ID || id[0] == DS18S20_ID ) {	 // temperature sensor
			
			uart_puts_P ("\r\n");
			
			ow_byte_wr( DS18X20_READ );			// read command
			
			for ( i=0 ; i< DS18X20_SP_SIZE; i++ )
				sp[i]=ow_byte_rd();
			
			show_sp_uart( sp, DS18X20_SP_SIZE );

			if ( crc8( &sp[0], DS18X20_SP_SIZE ) )
				uart_puts_P( " CRC FAIL " );
			else 
				uart_puts_P( " CRC O.K. " );
			uart_puts_P ("\r\n");
		
			meas = sp[0]; // LSB Temp. from Scrachpad-Data
			meas |= (uint16_t) (sp[1] << 8); // MSB
			
			uart_puts_P(" T_raw=");
			uart_puthex_byte((uint8_t)(meas>>8));
			uart_puthex_byte((uint8_t)meas);
			uart_puts_P(" ");

			if( id[0] == DS18S20_ID ) { // 18S20
				uart_puts_P( "S20/09" );
			}
			else if ( id[0] == DS18B20_ID ) { // 18B20
				i=sp[DS18B20_CONF_REG];
				if ( (i & DS18B20_12_BIT) == DS18B20_12_BIT ) {
					uart_puts_P( "B20/12" );
				}
				else if ( (i & DS18B20_11_BIT) == DS18B20_11_BIT ) {
					uart_puts_P( "B20/11" );
				}
				else if ( (i & DS18B20_10_BIT) == DS18B20_10_BIT ) {
					uart_puts_P( " B20/10 " );
				}
				else { // if ( (i & DS18B20_9_BIT) == DS18B20_9_BIT ) { 
					uart_puts_P( "B20/09" );
				}
			}			
			uart_puts_P(" ");
			
			DS18X20_meas_to_cel(id[0], sp, &subzero, &cel, &cel_frac_bits);
			
			DS18X20_uart_put_temp(subzero, cel, cel_frac_bits);
			
			uart_puts("\r\n");
			
		} // if meas-sensor
		
	} // loop all sensors