Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is some code that should allow you to read the device ID. I think your code was running to fast here is some code that I used to interface with the DS18B20. </p> <pre><code>/**************************************************************************** * temperature.h ****************************************************************************/ #ifndef TEMP_H #define TEMP_H extern double read_temp ( void ); extern void start_temp( void ); extern void Device_ID ( void ); #endif /**************************************************************************** * temperature.c ****************************************************************************/ void reset_ow(void); void write_ow(uint8_t b); uint8_t read_ow (void); #define OW_TEMP_SIG LATHbits.LATH0 #define OW_TEMP_TRIS TRISHbits.TRISH0 #define OW_TEMP_SIG_IN PORTHbits.RH0 #define DIR_OUT 0 #define DIR_IN 1 void Device_ID( void ) { uint8_t loop; uint8_t family; uint8_t checksum; uint8_t ROM_CODE[8]; // 1 byte CRC, 6 bytes SERIAL, 1 byte Family code reset_ow(); write_ow(0x33); // READ ROM COMMAND DS18B20 for(loop = 0; loop &lt; 8; loop++) // 1 byte in per time = 64-bits { ROM_CODE[loop] = read_ow(); } family = ROM_CODE[0]; checksum = ROM_CODE[7]; // add extra code to handle code } void start_temp(void) { uint8_t i; OW_TEMP_SIG=1; OW_TEMP_TRIS=DIR_OUT; for ( i=0;i&lt;100;i++) { Delay_us(100); } reset_ow(); write_ow(0xcc); // skip rom write_ow(0x44); // start t conv } double read_temp(void) { double temp=0; S16 itemp; reset_ow(); write_ow(0xcc); // skip rom write_ow(0xbe); // read scratch pad itemp=read_ow(); itemp|=(S16)read_ow()&lt;&lt;8; temp = itemp*(0.0625); OW_TEMP_TRIS=DIR_IN; OW_TEMP_SIG=1; return temp; } void reset_ow(void) { OW_TEMP_TRIS=DIR_OUT; OW_TEMP_SIG=0; Delay_us(250); Delay_us(250); OW_TEMP_TRIS=DIR_IN; OW_TEMP_SIG=1; Delay_us(250); Delay_us(250); } void write_ow(uint8_t b) { uint8_t i; OW_TEMP_SIG=1; OW_TEMP_TRIS=DIR_OUT; for ( i=0;i&lt;8;i++) { OW_TEMP_SIG=0; if ( b &amp; 0x01 ) { Delay_us(10); OW_TEMP_SIG=1; } Delay_us(70); OW_TEMP_SIG=1; Delay_us(10); b &gt;&gt;= 1; } OW_TEMP_TRIS=DIR_IN; OW_TEMP_SIG=1; } uint8_t read_ow(void) { uint8_t b=0; uint8_t m; uint8_t i; m=1; for ( i=0;i&lt;8;i++) { OW_TEMP_SIG=1; OW_TEMP_TRIS=DIR_OUT; OW_TEMP_SIG=0; Delay_us(8); OW_TEMP_TRIS=DIR_IN; OW_TEMP_SIG=1; Delay_us(15); if ( 1 == OW_TEMP_SIG_IN ) { b |= m; } m &lt;&lt;=1; Delay_us(60); } OW_TEMP_TRIS=DIR_IN; OW_TEMP_SIG=1; return b; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload