Exemple #1
0
static uint8_t search_sensors(void)
{
    uint8_t i;
    uint8_t id[OW_ROMCODE_SIZE];
    uint8_t diff, nSensors;

    uart_puts_P( NEWLINESTR "Scanning Bus for DS18X20" NEWLINESTR );

    ow_reset();

    nSensors = 0;

    diff = OW_SEARCH_FIRST;
    while ( diff != OW_LAST_DEVICE && nSensors < MAXSENSORS ) {
        DS18X20_find_sensor( &diff, &id[0] );

        if( diff == OW_PRESENCE_ERR ) {
            uart_puts_P( "No Sensor found" NEWLINESTR );
            break;
        }

        if( diff == OW_DATA_ERR ) {
            uart_puts_P( "Bus Error" NEWLINESTR );
            break;
        }

        for ( i=0; i < OW_ROMCODE_SIZE; i++ )
            gSensorIDs[nSensors][i] = id[i];

        nSensors++;
    }

    return nSensors;
}
Exemple #2
0
uint8_t search_sensors(void)
{
	uint8_t i;
	uint8_t id[OW_ROMCODE_SIZE];
	uint8_t diff, nSensors;

	nSensors = 0;

	for( diff = OW_SEARCH_FIRST;
		diff != OW_LAST_DEVICE && nSensors < MAXSENSORS ; )
	{
		DS18X20_find_sensor( &diff, &id[0] );

		if( diff == OW_PRESENCE_ERR ) {
			break;
		}

		if( diff == OW_DATA_ERR ) {
			break;
		}

		for (i=0;i<OW_ROMCODE_SIZE;i++) gSensorIDs[nSensors][i]=id[i];

		nSensors++;
	}

	return nSensors;
}
uint8_t search_sensors(void)
{
    uint8_t i;
    uint8_t id[OW_ROMCODE_SIZE];
    uint8_t diff, nSensors;

    ow_reset();

    nSensors = 0;

    diff = OW_SEARCH_FIRST;
    while ( diff != OW_LAST_DEVICE && nSensors < MAXSENSORS ) {
        DS18X20_find_sensor( &diff, &id[0] );

        if( diff == OW_PRESENCE_ERR ) {
//            CDC_Device_SendString (&VirtualSerial_CDC_InterfaceR, "No Sensor found \n\r");
            break;
        }

        if( diff == OW_DATA_ERR ) {
//            CDC_Device_SendString (&VirtualSerial_CDC_InterfaceR, "Bus Error \n\r");
            break;
        }

        for ( i=0; i < OW_ROMCODE_SIZE; i++ )
            gSensorIDs[nSensors][i] = id[i];

        nSensors++;
    }

    return nSensors;
}
Exemple #4
0
uint8_t search_sensors(void)
{
	uint8_t i;
	uint8_t id[OW_ROMCODE_SIZE];
	uint8_t diff, nSensors;

	//uart_puts_P( "\rScanning Bus for DS18X20\r" );

	nSensors = 0;

	for( diff = OW_SEARCH_FIRST;
		diff != OW_LAST_DEVICE && nSensors < MAXSENSORS ; )
	{
		DS18X20_find_sensor( &diff, &id[0] );

		if( diff == OW_PRESENCE_ERR ) {
			//uart_puts_P( "No Sensor found\r" );
			break;
		}

		if( diff == OW_DATA_ERR ) {
			//uart_puts_P( "Bus Error\r" );
			break;
		}

		for (i=0;i<OW_ROMCODE_SIZE;i++) gSensorIDs[nSensors][i]=id[i];

		nSensors++;
	}

	return nSensors;
}
Exemple #5
0
uint8_t search_sensors(void)
{
	uint8_t i;
	uint8_t id[OW_ROMCODE_SIZE];
	uint8_t diff, nSensors;

	nSensors = 0;
	
	for( diff = OW_SEARCH_FIRST;
	diff != OW_LAST_DEVICE && nSensors < MAXSENSORS ; )
	{
		DS18X20_find_sensor( &diff, &id[0] );
		
		if( diff == OW_PRESENCE_ERR ) {
			//wh1602b_putsP(PSTR("No sensor found"));
			break;
		}
		
		if( diff == OW_DATA_ERR ) {
			//wh1602b_putsP(PSTR("Bus error"));
			break;
		}
		
		for (i=0;i<OW_ROMCODE_SIZE;i++)
		gSensorIDs[nSensors][i]=id[i];
		
		nSensors++;
	}
	
	delay_ms(1000);
	return nSensors;
}
uint8_t search_sensors(uint8_t currBus)
{
//    uint8_t i;
    uint8_t id[OW_ROMCODE_SIZE];
    uint8_t diff;

    debug_puts( "?" );
    //	debug_puts( "Scan for DS18X20\n" );

    for( diff = OW_SEARCH_FIRST;
         (diff != OW_LAST_DEVICE) && (nTempSensors < N_TEMPERATURE_IN) ; )
    {
        DS18X20_find_sensor( &diff, &id[0] );

        if( diff == OW_PRESENCE_ERR )
        {
            //			debug_puts( "No Sensor\n" );
            debug_puts( "-" );
            break;
        }

        if( diff == OW_DATA_ERR )
        {
            REPORT_ERROR(ERR_FLAG_1WIRE_SCAN_FAULT);
            //			debug_puts( "Bus Error\n" );
            debug_puts( "B" );
            //ow_error_cnt++;
            //ow_bus_error_cnt[currBus];
            count_1w_bus_error( currBus );
            break;
        }

        //		debug_puts( "OK! got some!\n" );
        debug_puts( "+" );


#if OW_SERIAL_ID
        if(id[0] == DS2401_ID)
        {
            ow_copy_rom( serialNumber, id );
//            for( i=0; i < OW_ROMCODE_SIZE; i++ )
//                serialNumber[i]=id[i];
        }
        else
#endif
        {
#if N_TEMPERATURE_IN > 0
            ow_copy_rom( gTempSensorIDs[nTempSensors], id );
//            for( i=0; i < OW_ROMCODE_SIZE; i++)
//                gTempSensorIDs[nTempSensors][i]=id[i];

            gTempSensorBus[nTempSensors] = currBus;
#endif
            nTempSensors++;
        }

    }

    return nTempSensors;
}
int main(int argc, char *argv[]) {
  if (argc != 2) {
    puts("Path to COM port required.\n");
    return 1;
  }
  if (ow_init(argv[1])) {
    puts("Bus INIT failed. Check COM port.\n");
    return 1;
  }

  uint8_t c = 0, diff = OW_SEARCH_FIRST;
  int16_t temp_dc;

  while (diff != OW_LAST_DEVICE) {
    DS18X20_find_sensor(&diff, id);
    if (diff == OW_ERR_PRESENCE) {
      puts("All sensors are offline now.\n");
      ow_finit();
      return 1;
    }
    if (diff == OW_ERR_DATA) {
      puts("Bus error.\n");
      ow_finit();
      return 1;
    }
    fprintf(stdout, "Bus %s Device %03u Type 0x%02hx (%s) ID %02hx%02hx%02hx%02hx%02hx%02hx CRC 0x%02hx ", \
           argv[1], c, id[0], get_type_by_id(id[0]), id[6], id[5], id[4], id[3], id[2], id[1], id[7]);
    fflush(stdout);
    c ++;

    if (DS18X20_start_meas(DS18X20_POWER_EXTERN, NULL) == DS18X20_OK) {
      while (DS18X20_conversion_in_progress() == DS18X20_CONVERTING) {
        delay_ms(100); /* It will take a while */
      }
      if (DS18X20_read_decicelsius(id, &temp_dc) == DS18X20_OK) {
        /* Copied from my MCU code, so no float point */
        fprintf(stdout, "TEMP %3d.%01d C\n", temp_dc / 10, temp_dc > 0 ? temp_dc % 10 : -temp_dc % 10);
        continue;
      }
    }

    puts("MEASURE FAILED!\n");

  }
  puts("Sensors listed.\n");

  ow_finit();
  return 0;
}
uint8_t search_sensors(void)
{
	uint8_t i;
	uint8_t id[OW_ROMCODE_SIZE];
	uint8_t diff, nSensors;
	
	
	ow_reset();
	
	nSensors = 0;
	
	diff = OW_SEARCH_FIRST;
	while ( diff != OW_LAST_DEVICE && nSensors < MAXSENSORS ) 
	{
		DS18X20_find_sensor( &diff, &id[0] );
		
		if( diff == OW_PRESENCE_ERR ) 
		{
			lcd_gotoxy(0,1);
			lcd_puts("No Sensor found\0" );
			break;
		}
		
		if( diff == OW_DATA_ERR ) 
		{
			lcd_gotoxy(0,1);
			lcd_puts("Bus Error\0" );
			break;
		}
		lcd_gotoxy(4,1);

		for ( i=0; i < OW_ROMCODE_SIZE; i++ )
			{
				//lcd_gotoxy(15,1);
				//lcd_puthex(id[i]);

			gSensorIDs[nSensors][i] = id[i];
			//delay_ms(100);
			}
			
		nSensors++;
	}
	
	return nSensors;
}
Exemple #9
0
void temperature_init(void)
{
    ow_reset();
    
    uint8_t diff = OW_SEARCH_FIRST;
    
    while(diff != OW_LAST_DEVICE) {
        DS18X20_find_sensor(&diff, id);
        
        if( diff == OW_PRESENCE_ERR ) {
//            debug('E', "no sensor");
            break;
        }

        if( diff == OW_DATA_ERR ) {
//            debug('E', "bus error");
            break;
        }
        
//        debug('I', "sensor id %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]);
    }
}
int main (void) {            // (2)
   ledidx_t i;

   DDRB  = 0xFF;  // Port B: 1 = output
   PORTB = 0x01;  //bootup 1

   //_delay_ms(1000);

   // Initialize LCD Display
   DDRC |= (1<<PC1) | (1<<PC3); //PC1 = R/W, PC3 = Backlight control
   PORTC &= ~(1<<PC1);
   //Switch Backlight on:
   PORTC |= (1<<PC3);

   _delay_ms(10); lcd_init();

   PORTB = 0x02;  //bootup 2
   _delay_ms(100);
   lcd_string_P(PSTR("blinkylight 0.3 "));
   lcd_setcursor(0,2);
   lcd_string_P(PSTR("Booting ...     "));
   //PORTB = 0x03;  //bootup 3
   //_delay_ms(1000);

   uart_init();
   uart_putc('p'); uart_putc('w'); uart_putc('r'); uart_putc('O'); uart_putc('N'); uart_putc('\n');
   //PORTB = 0x04;  //bootup 4



   //PORTB = 0x05;  //bootup 5

   // Enable Interrupts
   sei();
   PORTB = 0x06;  //bootup 6

   // muss vor ws2801_init stehen, da dieser PA1 und PA2 als output schaltet
   DDRA  = 0x00; // Port A: 0 = input
   PORTA = 0x00;  //        0 = pull-ups off

   //PORTB = 0x0a;  //bootup a


   PORTB = 0x00;  //bootup d
   lcd_setcursor(0,2);
   lcd_string_P(PSTR("Boot complete  "));
   _delay_ms(10);

   //Switch Backlight off:
   PORTC &= ~(1<<PC3);

   // Enter main loop
   uint8_t dezisek = 0;
#define DEZISEKTHRES 4
   while(1) {                // (5)
     /* "leere" Schleife*/   // (6)
     _delay_ms(25);
     //pb_scroll <<= 1;
     //if (pb_scroll == 0b00010000) pb_scroll = 0b00000001;
     //PORTB &= 0b11110000;
     //PORTB |= pb_scroll;
     PORTB ^= (1<<PB2);
     if (dezisek > DEZISEKTHRES) {
       if (relay_timer > 0) {
         relay_timer --;
         if (relay_timer == 0) relay_reset = 1;
         else {
           PORTB ^= ( 1 << PB5 )|(1<<PB6)|(1<<PB7);
         }
       }
     }
     dezisek++;
     if (disp_set) {
       lcd_clear();
       lcd_home();

       for(i=0;i<16;i++)lcd_data(disp_buf[i]);
       lcd_setcursor(0,2);
       for(;i<32;i++)lcd_data(disp_buf[i]);

       disp_set = 0;
       _delay_ms(250);
     }
     if (relay_set) {
       PORTB |= (1<<PB4);
       PORTB |= (1<<PB5)|(1<<PB6)|(1<<PB7);
       relay_set = 0;
     }
     if (relay_reset) {
       PORTB &= ~(1<<PB4);
       PORTB &= ~((1<<PB5)|(1<<PB6)|(1<<PB7));
       relay_reset = 0; relay_timer = 0;
     }
     if (PINA & (1<<PA7)) {
       uart_putc('5');
     }
     if (PINA & (1<<PA6)) {
       uart_putc('4');
     }
     if (PINA & (1<<PA5)) {
       uart_putc('3');
     }
     if (PINA & (1<<PA4)) {
       uart_putc('2');
     }
     if (measure_temp == 1) {
       //PORTC ^= (1<<PC3);
       uint8_t sensor_id[OW_ROMCODE_SIZE];
       uint8_t diff = OW_SEARCH_FIRST;
       ow_reset();
       DS18X20_find_sensor(&diff, &sensor_id[0]);
       if (diff == OW_PRESENCE_ERR)
           strcpy_P(&disp_tmp_buf[0], PSTR("Err:Presence     "));
       else if (diff == OW_DATA_ERR)
           strcpy_P(&disp_tmp_buf[0], PSTR("Err:Data         "));
       else {
         if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) {
           _delay_ms( DS18B20_TCONV_12BIT );
           int16_t decicelsius;
           if ( DS18X20_read_decicelsius( &sensor_id[0], &decicelsius) == DS18X20_OK ) {
             disp_tmp_buf[0]='T'; disp_tmp_buf[1]='e'; disp_tmp_buf[2]='m'; disp_tmp_buf[3]='p'; disp_tmp_buf[4]=':'; disp_tmp_buf[5]=' ';
             DS18X20_format_from_decicelsius( decicelsius, &disp_tmp_buf[6], 8 );
           } else {
             strcpy_P(&disp_tmp_buf[0], PSTR("Err: Read        "));
           }
         } else {
             strcpy_P(&disp_tmp_buf[0], PSTR("Err: StartMeasure"));
         }
       }
       sprintf(&disp_tmp_buf[16], "%d bytes recv.", recv_len);
       //disp_show_buf(&disp_tmp_buf[0]);
       for(i=0;i<20;i++) uart_putc(disp_tmp_buf[i]);
       measure_temp=0;
     }
     if (PINA & (1<<PA3)) {
       relay_set = 1;
       relay_timer = 10;
       uart_putc('1');
     }
     //uart_putc('+');
//     uart_putc('\n');
   }                         // (7)
   /* wird nie erreicht */
   return 0;                 // (8)
}
Exemple #11
0
/**
 * \ingroup usartcmdline
 * \b OWREAD-Befehl DS18x20 auf Bus suchen und anzeigen
 */
int16_t command_OWlookup(char *outbuffer)
{
	if (outbuffer)					// nur bei USART
		return cmd_502(outbuffer);

	#if USE_OW
	uint8_t i;
	uint8_t diff, nSens;
	uint16_t TWert;
	uint8_t subzero, cel, cel_frac_bits;
	uint8_t gSensorIDs[MAXLOOKUP][OW_ROMCODE_SIZE];
	
	usart_write("\r\nScanning Bus for DS18X20");
	
	nSens = 0;
	
	for( diff = OW_SEARCH_FIRST; 
		diff != OW_LAST_DEVICE && nSens < MAXLOOKUP ;  )
	{
		DS18X20_find_sensor( &diff, &gSensorIDs[nSens][0] );
		
		if( diff == OW_PRESENCE_ERR ) {
			usart_write("\r\nNo Sensor found");
			break;
		}
		
		if( diff == OW_DATA_ERR ) {
			usart_write("\r\nBus Error");
			break;
		}
		
		nSens++;
	}
	usart_write("\n\r%i 1-Wire Sensoren gefunden.\r\n", nSens);

//	for (i=0; i<nSens; i++) {
//		// set 10-bit Resolution - Alarm-low-T 0 - Alarm-high-T 85
//		DS18X20_write_scratchpad( &gSensorIDs[i][0] , 0, 85, DS18B20_12_BIT);
//	}

	for (i=0; i<nSens; i++) {
		usart_write("\r\n#%i ist ein ",(int) i+1);
		if ( gSensorIDs[i][0] == DS18S20_ID)
			usart_write("DS18S20/DS1820");
		else usart_write("DS18B20");

		usart_write(" mit ");
		if ( DS18X20_get_power_status( &gSensorIDs[i][0] ) ==
			DS18X20_POWER_PARASITE ) 
			usart_write( "parasitaerer" );
		else usart_write( "externer" ); 
		usart_write( " Spannungsversorgung. " );

		// T messen
		if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, &gSensorIDs[i][0] ) == DS18X20_OK ) {
				_delay_ms(DS18B20_TCONV_12BIT);
				if ( DS18X20_read_meas( &gSensorIDs[i][0], &subzero,
						&cel, &cel_frac_bits) == DS18X20_OK ) {
					DS18X20_show_id_uart( &gSensorIDs[i][0], OW_ROMCODE_SIZE );
					TWert = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);
					usart_write(" %i %i.%4i C %i",subzero, cel, cel_frac_bits,TWert);
				}
				else usart_write(" CRC Error (lost connection?)");
			}
			else usart_write(" *** Messung fehlgeschlagen. (Kurzschluss?) ***");
	}
	
	#endif
	return 0;
}