This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:sensor:1-wire [2012/06/07 06:42] – mikk.leini | en: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 " | 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 " | ||
| - | [{{ : | + | [{{ : |
| [{{ : | [{{ : | ||
| Line 43: | Line 43: | ||
| Example code enabling to read the temperature with 1-wire protocol is shown below. It is important to include | Example code enabling to read the temperature with 1-wire protocol is shown below. It is important to include | ||
| - | ~~PB~~ | + | < |
| <code c> | <code c> | ||
| Line 51: | Line 51: | ||
| #include " | #include " | ||
| #include " | #include " | ||
| - | |||
| #include < | #include < | ||
| #include < | #include < | ||
| #include < | #include < | ||
| - | // | ||
| // Sensor queue number and sensor' | // Sensor queue number and sensor' | ||
| - | // | ||
| 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' | // Multiplexer' | ||
| - | // 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, | DS18X20_format_from_decicelsius( decicelsius, | ||
| - | |||
| - | // 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); | ||
| } | } | ||
| } | } | ||
| </ | </ | ||