Example #1
0
void w1_command(uint8_t command, uint8_t* id)
{
  uint8_t i;
  w1_reset();
  if( id ){
    w1_byte_wr( MATCH_ROM );			// to a single device
    i = 8;
    do{
      w1_byte_wr( *id );
      id++;
    }while( --i );
  }else{
    w1_byte_wr( SKIP_ROM );			// to all devices
  }
  w1_byte_wr( command );
}
Example #2
0
uint16_t read_meas(void)
{
  uint8_t id[8], diff;
  //uint8_t s[30];
  uint8_t i;
  uint16_t temp = 0;

  for( diff = SEARCH_FIRST; diff != LAST_DEVICE; ){
    diff = w1_rom_search( diff, id );

    if( diff == PRESENCE_ERR ){
      //uputsnl( "No Sensor found" );
      break;
    }
    if( diff == DATA_ERR ){
      //uputsnl( "Bus Error" );
      break;
    }
    if( id[0] == 0x28 || id[0] == 0x10 ){	// temperature sensor
      //uputs( "ID: " );
      for( i = 0; i < 8; i++ ){
	//sprintf( s, "%02X ", id[i] );
	//uputs( s );
      }
      w1_byte_wr( READ );			// read command
      temp = w1_byte_rd();			// low byte
      temp |= (uint16_t)w1_byte_rd() << 8;		// high byte
      if( id[0] == 0x10 )			// 9 -> 12 bit
        temp <<= 3;
      //sprintf( s, "  T: %04X = ", temp );	// hex value
      //uputs( s );
      //sprintf( s, "%4d.%01d¯C", temp >> 4, (temp << 12) / 6553 ); // 0.1¯C
      //uputsnl( s );
    }
  }
  //uputsnl( "" );
  
  return (temp >> 4) * 100 + ((temp << 12) / 6553) * 10;
  //return temp >> 4;
}
Example #3
0
void read_meas( void )
{
	uchar id[8], diff;
	uchar s[30];
	uchar i;
	uint temp;

	for( diff = SEARCH_FIRST; diff != LAST_DEVICE; )
	{
		diff = w1_rom_search( diff, id );

		if( diff == PRESENCE_ERR )
		{
			uputsnl( "No Sensor found" );
			break;
		}
		if( diff == DATA_ERR )
		{
			uputsnl( "Bus Error" );
			break;
		}
		if( id[0] == 0x28 || id[0] == 0x10 ) // temperature sensor
		{
			uputs( "ID: " );
			for( i = 0; i < 8; i++ ){
				sprintf( s, "%02X ", id[i] );
				uputs( s );
			}
			w1_byte_wr( READ );			// read command
			temp = w1_byte_rd();			// low byte
			temp |= (uint)w1_byte_rd() << 8;		// high byte
			if( id[0] == 0x10 )			// 9 -> 12 bit
				temp <<= 3;
			sprintf( s, "  T: %04X = ", temp );	// hex value
			uputs( s );
			sprintf( s, "%4d.%01d�C", temp >> 4, (temp << 12) / 6553 ); // 0.1�C
			uputsnl( s );
		}
	}
Example #4
0
uint read_meas( void )
{
    uchar id[8], diff;
    uchar i;
    uint temp;

    for( diff = SEARCH_FIRST; diff != LAST_DEVICE; ) {
        diff = w1_rom_search( diff, id );

        if( diff == PRESENCE_ERR ) {
            //printf( "No Sensor found" );
            break;
        }
        if( diff == DATA_ERR ) {
            //printf( "Bus Error" );
            break;
        }
        if( id[0] == 0x28 || id[0] == 0x10 ) {	// temperature sensor
            //LCD_setpos(0,0);

            for( i = 0; i < 8; i++ ) {
//	printf("%02X", id[i] );    ID

            }
            w1_byte_wr( READ );			// read command
            temp = w1_byte_rd();			// low byte
            temp |= (uint)w1_byte_rd() << 8;		// high byte
            if( id[0] == 0x10 )			// 9 -> 12 bit
                temp <<= 3;
            //LCD_setpos(1,0);

            return temp;

        }
    }
    return 0;
}
Example #5
0
uint8_t w1_rom_search(uint8_t diff, uint8_t* id)
{
  uint8_t i, j, next_diff;
  uint8_t b;

  if( w1_reset() )
    return PRESENCE_ERR;			// error, no device found
  w1_byte_wr( SEARCH_ROM );			// ROM search command
  next_diff = LAST_DEVICE;			// unchanged on last device
  i = 8 * 8;					// 8 bytes
  do{
    j = 8;					// 8 bits
    do{
      b = w1_bit_io( 1 );			// read bit
      if( w1_bit_io( 1 ) ){			// read complement bit
	if( b )					// 11
	  return DATA_ERR;			// data error
      }else{
	if( !b ){				// 00 = 2 devices
	  if( diff > i ||
	    ((*id & 1) && diff != i) ){
	    b = 1;				// now 1
	    next_diff = i;			// next pass 0
	  }
	}
      }
      w1_bit_io( b );     			// write bit
      *id >>= 1;
      if( b )					// store bit
	*id |= 0x80;
      i--;
    }while( --j );
    id++;					// next byte
  }while( i );
  return next_diff;				// to continue search
}
Example #6
0
uint8_t w1_byte_rd(void)
{
  return w1_byte_wr( 0xFF );
}