Exemple #1
0
// see http://www.maxim-ic.com/app-notes/index.mvp/id/162
uint8_t ow_reset(void)
{
        uint8_t err;
        OW_DIR_OUT_LOW(); // pull OW-Pin low for 480us
        
        ow_delay_us(233);  // min 480us in total
        ow_delay_us(233);
        
        // set Pin as input - wait for clients to pull low
        OW_DIR_IN(); // input and pull up
        ow_delay_us(53);   // 60 us
        err = ow_input_pin_state(); // devices should now pull low
        // nobody pulled to low, still high-> error
        // after a delay the clients should release the line
        // and input-pin gets back to high due to pull-up-resistor
        ow_delay_us(233);  // max 240us in total
        if (err==1){
                return(1); // no presence puls
        }
        if( ow_input_pin_state() == 0 )                // short circuit
                return(1);
        return(0);
}
Exemple #2
0
/* start measurement (CONVERT_T) for all sensors if input id==NULL
   or for single sensor. then id is the rom-code */
uint8_t DS18X20_start_meas( uint8_t with_power_extern, uint8_t id[])
{
	ow_reset(); //**
	if( ow_input_pin_state() ) { // only send if bus is "idle" = high
		ow_command( DS18X20_CONVERT_T, id );
		if (with_power_extern != DS18X20_POWER_EXTERN)
			ow_parasite_enable();
		return DS18X20_OK;
	}
	else {

		return DS18X20_START_FAIL;
	}
}
Exemple #3
0
uint8_t DS18X20_read_scratchpad( uint8_t id[], uint8_t sp[] )
{
	uint8_t i;

	ow_reset(); //**
	if( ow_input_pin_state() ) { // only send if bus is "idle" = high
		ow_command( DS18X20_READ, id );
		for ( i=0 ; i< DS18X20_SP_SIZE; i++ )	sp[i]=ow_byte_rd();
		return DS18X20_OK;
	}
	else {

		return DS18X20_ERROR;
	}
}
Exemple #4
0
/* start measurement (CONVERT_T) for all sensors if input id==NULL
   or for single sensor. then id is the rom-code */
uint8_t DS18X20_start_meas(uint8_t with_power_extern, uint8_t id[])
{
	ow_reset(); //**
	if (ow_input_pin_state()) {  // only send if bus is "idle" = high
		ow_command(DS18X20_CONVERT_T, id);
		if (with_power_extern != DS18X20_POWER_EXTERN)
			ow_parasite_enable();
		return DS18X20_OK;
	} else {
#ifdef DS18X20_VERBOSE
		printf_P(PSTR("DS18X20_start_meas: Short Circuit !\r"));
#endif
		return DS18X20_START_FAIL;
	}
}
Exemple #5
0
uint8_t ow_bit_io( uint8_t b )
{
        
        OW_DIR_OUT_LOW(); // drive bus low
        ow_delay_us(1); // Recovery-Time 
        if ( b ) {
                OW_DIR_IN(); // if bit is 1 set bus high (by ext. pull-up)
        }
        // wuffwuff delay was 15uS-1 see comment above
        ow_delay_us(7);
        b=ow_input_pin_state();
        ow_delay_us(50);
        OW_DIR_IN();
        return b;
}
Exemple #6
0
uint8_t DS18X20_recall_E2( uint8_t id[] )
{
	ow_reset(); //**
	if( ow_input_pin_state() ) { // only send if bus is "idle" = high
		ow_command( DS18X20_RECALL_E2, id );
		// TODO: wait until status is "1" (then eeprom values
		// have been copied). here simple delay to avoid timeout
		// handling
		_delay_ms(10);
		return DS18X20_OK;
	}
	else {

		return DS18X20_ERROR;
	}
}
Exemple #7
0
uint8_t DS18X20_write_scratchpad( uint8_t id[],
	uint8_t th, uint8_t tl, uint8_t conf)
{
	ow_reset(); //**
	if( ow_input_pin_state() ) { // only send if bus is "idle" = high
		ow_command( DS18X20_WRITE_SCRATCHPAD, id );
		ow_byte_wr(th);
		ow_byte_wr(tl);
		if (id[0] == DS18B20_ID) ow_byte_wr(conf); // config avail. on B20 only
		return DS18X20_OK;
	}
	else {

		return DS18X20_ERROR;
	}
}
Exemple #8
0
uint8_t DS18X20_read_scratchpad(uint8_t id[], uint8_t sp[])
{
	uint8_t i;

	ow_reset(); //**
	if (ow_input_pin_state()) {  // only send if bus is "idle" = high
		ow_command(DS18X20_READ, id);
		for (i = 0 ; i < DS18X20_SP_SIZE; i++)	sp[i] = ow_byte_rd();
		return DS18X20_OK;
	} else {
#ifdef DS18X20_VERBOSE
		printf_P(PSTR("DS18X20_read_scratchpad: Short Circuit !\r"));
#endif
		return DS18X20_ERROR;
	}
}
Exemple #9
0
uint8_t DS18X20_recall_E2(uint8_t id[])
{
	ow_reset(); //**
	if (ow_input_pin_state()) {  // only send if bus is "idle" = high
		ow_command(DS18X20_RECALL_E2, id);
		// TODO: wait until status is "1" (then eeprom values
		// have been copied). here simple delay to avoid timeout
		// handling
		_delay_ms(DS18X20_COPYSP_DELAY);
		return DS18X20_OK;
	} else {
#ifdef DS18X20_VERBOSE
		printf_P(PSTR("DS18X20_recall_E2: Short Circuit !\r"));
#endif
		return DS18X20_ERROR;
	}
}
Exemple #10
0
uint8_t DS18X20_write_scratchpad(uint8_t id[],
                                 uint8_t th, uint8_t tl, uint8_t conf)
{
	ow_reset(); //**
	if (ow_input_pin_state()) {  // only send if bus is "idle" = high
		ow_command(DS18X20_WRITE_SCRATCHPAD, id);
		ow_byte_wr(th);
		ow_byte_wr(tl);
		if (id[0] == DS18B20_ID) ow_byte_wr(conf); // config avail. on B20 only
		return DS18X20_OK;
	} else {
#ifdef DS18X20_VERBOSE
		printf_P(PSTR("DS18X20_write_scratchpad: Short Circuit !\r"));
#endif
		return DS18X20_ERROR;
	}
}
Exemple #11
0
uint8_t DS18X20_copy_scratchpad( uint8_t with_power_extern,
	uint8_t id[] )
{
	ow_reset(); //**
	if( ow_input_pin_state() ) { // only send if bus is "idle" = high
		ow_command( DS18X20_COPY_SCRATCHPAD, id );
		if (with_power_extern != DS18X20_POWER_EXTERN)
			ow_parasite_enable();
		_delay_ms(10); // wait for 10 ms
		if (with_power_extern != DS18X20_POWER_EXTERN)
			ow_parasite_disable();
		return DS18X20_OK;
	}
	else {

		return DS18X20_START_FAIL;
	}
}
Exemple #12
0
uint8_t DS18X20_copy_scratchpad(uint8_t with_power_extern,
                                uint8_t id[])
{
	ow_reset(); //**
	if (ow_input_pin_state()) {  // only send if bus is "idle" = high
		ow_command(DS18X20_COPY_SCRATCHPAD, id);
		if (with_power_extern != DS18X20_POWER_EXTERN)
			ow_parasite_enable();
		_delay_ms(DS18X20_COPYSP_DELAY); // wait for 10 ms
		if (with_power_extern != DS18X20_POWER_EXTERN)
			ow_parasite_disable();
		return DS18X20_OK;
	} else {
#ifdef DS18X20_VERBOSE
		printf_P(PSTR("DS18X20_copy_scratchpad: Short Circuit !\r"));
#endif
		return DS18X20_START_FAIL;
	}
}
Exemple #13
0
/* Timing issue when using runtime-bus-selection (!OW_ONE_BUS):
   The master should sample at the end of the 15-slot after initiating
   the read-time-slot. The variable bus-settings need more
   cycles than the constant ones so the delays had to be shortened 
   to achive a 15uS overall delay 
   Setting/clearing a bit in I/O Register needs 1 cyle in OW_ONE_BUS
   but around 14 cyles in configureable bus (us-Delay is 4 cyles per uS) */
uint8_t ow_bit_io1( uint8_t b )
{
        
        OW_DIR_OUT_LOW(); // drive bus low
        ow_delay_us(1); // Recovery-Time 1us
        if ( b ) {
                OW_DIR_OUT_HIGH(); 
        }else{
                OW_DIR_OUT_LOW();
        }
        ow_delay_us(38);
        OW_DIR_IN(); 
        ow_delay_us(2); // Recovery-Time 1us
        // wuffwuff delay was 15uS-1 see comment above
        OW_DIR_OUT_LOW(); // drive bus low
        ow_delay_us(1); // Recovery-Time 1us
        OW_DIR_IN(); 
        ow_delay_us(7);
        b=ow_input_pin_state();
        ow_delay_us(38);
        return b;
}