Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:examples:sensor:1-wire [2012/06/07 06:42] mikk.leinien:examples:sensor:1-wire [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 12: Line 12:
 1-wire communication is mostly used for communicating between different sensors and memory units. Bus data transfer rate is approximately 16.3 kbit/s. Communication is started by a master with the "reset" pulse, which pulls the wire to 0 volts for at least 480 µs. This signal resets all devices on the bus, simply taking the power out from the bus. After that, any device on the bus, shows that it exists with a "presence" pulse by holding the wire to ground at least 60 µs after the master releases the bus. With following 8-bit command and then data can be sent or received in groups of 8-bits. Each device on the bus has a unique 64-bit serial identification number. 1-wire communication is mostly used for communicating between different sensors and memory units. Bus data transfer rate is approximately 16.3 kbit/s. Communication is started by a master with the "reset" pulse, which pulls the wire to 0 volts for at least 480 µs. This signal resets all devices on the bus, simply taking the power out from the bus. After that, any device on the bus, shows that it exists with a "presence" pulse by holding the wire to ground at least 60 µs after the master releases the bus. With following 8-bit command and then data can be sent or received in groups of 8-bits. Each device on the bus has a unique 64-bit serial identification number.
  
-[{{  :et:examples:sensor:ds_network2.jpg?500  |1-wire sensor connection}}]+[{{  :et:examples:sensor:ds_network2.jpg?500  |1-wire sensors connection}}]
  
 [{{  :en:examples:sensor:1_wire.png?300| Data transfer on a 1-wire bus}}] [{{  :en:examples:sensor:1_wire.png?300| Data transfer on a 1-wire bus}}]
Line 43: Line 43:
 Example code enabling to read the temperature with 1-wire protocol is shown below. It is important to include  "onewire.h" and "onewire.c" to the program. Sensor-specific code is located in "ds18x20.h" and "ds18x20.c" files. Example code enabling to read the temperature with 1-wire protocol is shown below. It is important to include  "onewire.h" and "onewire.c" to the program. Sensor-specific code is located in "ds18x20.h" and "ds18x20.c" files.
  
-~~PB~~+<pagebreak>
  
 <code c> <code c>
Line 51: Line 51:
 #include "onewire.h" #include "onewire.h"
 #include "ds18x20.h" #include "ds18x20.h"
- 
 #include <homelab/module/lcd_gfx.h> #include <homelab/module/lcd_gfx.h>
 #include <homelab/delay.h> #include <homelab/delay.h>
 #include <homelab/pin.h> #include <homelab/pin.h>
  
-// 
 // Sensor queue number and sensor's specific code are stored here // Sensor queue number and sensor's specific code are stored here
-// 
 extern uint8_t gSensorIDs[MAXSENSORS][OW_ROMCODE_SIZE]; extern uint8_t gSensorIDs[MAXSENSORS][OW_ROMCODE_SIZE];
  
 +// Main program
 int main( void ) int main( void )
 { {
Line 82: Line 80:
    
   // Multiplexer's pin configuration as a output and then switchover it     // Multiplexer's pin configuration as a output and then switchover it  
-  // to connect external sensor with the controller .+  // to connect external sensor with the controller.
   pin_setup_output(multiplexer_pin);   pin_setup_output(multiplexer_pin);
   pin_set(multiplexer_pin);    pin_set(multiplexer_pin); 
Line 125: Line 123:
      // Making the readings to strings and adding +/-.      // Making the readings to strings and adding +/-.
      DS18X20_format_from_decicelsius( decicelsius, s, 10 );      DS18X20_format_from_decicelsius( decicelsius, s, 10 );
- 
-     // If is needed maximum accuracy use this function:  
-     // DS18X20_format_from_maxres( tval, s, 10 ); 
  
      // Displaying the temprerature      // Displaying the temprerature
Line 144: Line 139:
      error++;      error++;
    }    }
-  
  }  }
  else   else 
  {  {
-   // Taking the measurements failed, maybe in data bus has a short circuit  
    error++;    error++;
  }  }
Line 164: Line 157:
  lcd_gfx_write_string("        ");  lcd_gfx_write_string("        ");
     }     }
- 
     sw_delay_ms(500);     sw_delay_ms(500);
   }   }
 } }
 </code> </code>
en/examples/sensor/1-wire.1339051362.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0