Beispiel #1
0
int ds_search_rom(uint8_t *id, uint8_t mask)
{
	uint8_t r, i, j;
	uint8_t crc, b1, b2;
	
	/* Reset the sensor(s) */
	r = ds_reset();
	if(r != DS_OK) return(r);
	
	/* Transmit the SEARCH ROM command */
	ds_write_byte(0xF0);
	
	/* An ID is made up of 8 bytes (7 + CRC) */
	for(crc = i = 0; i < 8; i++)
	{
		*id = 0;
		
		for(j = 0; j < 8; j++)
		{
			/* Read the bit and its complement */
			b1 = ds_read_bit();
			b2 = ds_read_bit();
			
			/* Both bits should never be 1 */
			if(b1 && b2) return(DS_ERROR);
			
			/* Both bits are 0 when two or more sensors
			 * respond with a different value */
			if(b1 == b2)
			{
				b1 = mask & 1;
				mask >>= 1;
				
				/* Test if this is the last ID on the bus */
				if(!b1) r = DS_MORE;
			}
			
			/* Let the sensors know which direction we're going */
			ds_write_bit(b1);
			
			*id >>= 1;
			if(b1) *id |= 1 << 7;
		}
		
		/* Update the CRC, compare with last byte */
		if(i != 7) crc = _crc_ibutton_update(crc, *id);
		else if(crc != *id) return(DS_BADCRC);
		
		id++;
	}
/* Read a whole byte from the device.
 */
static unsigned int ds_read_byte (DALLAS_CONTEXT *dc)
{
  int x;
  unsigned int data;

  data = 0;
  for (x = 0; x < 8; x++) {
    data |= ((ds_read_bit(dc) ? 1 : 0) << x);
  }

  return data;
} /* ds_read_byte */
Beispiel #3
0
static uint8_t ds_read_byte()
{
	uint8_t i, b = 0;
	
	for(i = 0; i < 8; i++)
	{
		b >>= 1;
		if(ds_read_bit()) b |= 1 << 7;
	}
	
	return(b);
}
Beispiel #4
0
//*----------------------------------------------------------------------------
//* Name     : ds_read_byte()
//* Brief    : Read byte from bus
//* Argument : None
//* Return   : 8 bits Data
//*----------------------------------------------------------------------------
static int ds_read_byte() {
	int i = 0;
	uint8 buf = 0;
	
	for(i = 0; i < 8; i ++) {
		buf >>= 1;
		// LSB First	
		if(ds_read_bit()) {
			buf |= 0x80;	
		}
	}
	return buf;	
}
Beispiel #5
0
unsigned char ds_read_byte() {
        unsigned char dsbyte,cnt = 0;
        //cli();
        do {
                if (ds_read_bit()) {
                        dsbyte |= (1<<7);
                } else {
                        dsbyte &= ~(1<<7);
                }
                if (cnt<7) {
                        dsbyte = dsbyte>>1;
                }
                cnt++;
        } while (cnt<8);