Note that there are some explanatory texts on larger screens.

plurals
  1. PO1wire problem in detail
    text
    copied!<p>I have defined these functions below, and when I ask Device_ID function for example of the family code, I only get FF (should be 28), acctually I get both the family code, 48-bit serial, and the crc 8 bit to be all "ones". It seems like the detect slave device function works as it should.... If i connect the slave he say's I am here, and if i take it away... no device present. I also have a 5kohm pull-up at the 1wire.</p> <p>And I dont have a clue why my Device_ID dont work, so my question is why doesnt it work!? can u see anything wrong within this code (Im using a PIC 18F87J50 and one DS18B20):</p> <p>My statement in Main:</p> <pre><code> OSCTUNEbits.PLLEN = 1; Init_Registers(); Init_Settings(); Init_Ports(); Init_Glcd(); Detect_Slave_Device(); Device_ID( 0x33 ); </code></pre> <p>Used functions:</p> <pre><code> void Detect_Slave_Device(void){ uint8_t value; OW_reset_pulse(); if (OW_reset_pulse()) { Display_Cls(); Display_StringAt("No Device Present!",5,6); Delay_1sec(); Delay_1sec(); } else { Display_Cls(); Display_StringAt("Device Present!",5,6); Delay_1sec(); Delay_1sec(); }} </code></pre> <hr> <pre><code> uint8_t OW_reset_pulse(void){ uint8_t presence_detect; drive_OW_low(); // Drive the bus low Delay_us(200); // Delay at least 480 microsecond (us) Delay_us(200); Delay_us(85); drive_OW_high (); // Release the bus // Here should the client drive low Delay_us(50); // Delay 50 microsecond (us) presence_detect = read_OW(); // Sample for presence pulse from slave Delay_us(200); // Delay 435 microsecond (us) Delay_us(200); Delay_us(35); drive_OW_high (); // Release the bus return presence_detect;} </code></pre> <hr> <pre><code> void drive_OW_low (void){ LATHbits.LATH0 = 0; TRISHbits.TRISH0 = 0; }// Output </code></pre> <hr> <pre><code> void drive_OW_high (void){ LATHbits.LATH0 = 0; TRISHbits.TRISH0 = 1;} // Input </code></pre> <hr> <pre><code> uint8_t read_OW (void){ unsigned char read_data=0; TRISHbits.TRISH0 = 1; if (1 == PORTHbits.RH0) read_data = 1; else read_data = 0; return read_data;} </code></pre> <p>And now some ofthe important device_id:</p> <pre><code> void Device_ID( uint8_t command ){ uint8_t loop, family, checksum, ROM_CODE[8]; // 1 byte CRC, 6 bytes SERIAL, 1 byte Family code static char container[1]; OW_reset_pulse(); OW_write_byte( 0x33 ); // READ ROM COMMAND DS18B20 for(loop = 0; loop &lt; 9; loop++) // 1 byte in per time = 64-bits { ROM_CODE[loop] = OW_read_byte(); } family = ROM_CODE[1]; checksum = ROM_CODE[8]; And so on = Print MY VALUES -&gt; </code></pre> <hr> <pre><code> void OW_write_byte (uint8_t write_data){ uint8_t loop; for (loop = 0; loop &lt; 8; loop++) { OW_write_bit(write_data &amp; 0x01); //Sending LS-bit first write_data &gt;&gt;= 1; // shift the data byte for the next bit to send } } </code></pre> <hr> <pre><code> void OW_write_bit (uint8_t write_bit){ if (write_bit) // Write 1 time slot { Brakepoint(); // 1 us //writing a bit '1' drive_OW_low(); // Drive the bus low Delay_us(6); // Delay 6 microsecond (us) drive_OW_high (); // Release the bus Delay_us(64);; // Delay 64 microsecond (us) } else // Write 0 time slot { Brakepoint(); // 1 us //writing a bit '0' drive_OW_low(); // Drive the bus low Delay_us(65); // Delay 65 microsecond (us) drive_OW_high (); // Release the bus Delay_us(10); // Delay 10 microsecond for recovery (us) }} </code></pre> <hr> <pre><code> uint8_t OW_read_byte (void) uint8_t loop, result=0; for (loop = 0; loop &lt; 8; loop++) { result &gt;&gt;= 1; // shift the result to get it ready for the next bit to receive if (OW_read_bit()) result |= 0x80; // if result is one, then set MS-bit } return result; } </code></pre> <hr> <pre><code> uint8_t OW_read_bit (void){ uint8_t read_data; // Reading a bit Brakepoint(); // 1 us drive_OW_low(); // Drive the bus low Delay_us(6); // delay 6 microsecond (us) drive_OW_high (); // Release the bus Delay_us(9); // delay 9 microsecond (us) read_data = read_OW(); //Read the status of OW_PIN Delay_us(55); // delay 55 microsecond (us) return read_data;} </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