CONFIG 1WIRE/de

(Difference between revisions)
Jump to: navigation, search
(Beschreibung)
(Beschreibung)
Line 36: Line 36:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
Der CONFIG 1WIRE Befehl überschreibt die Compiler-Einstellungen.  
+
Der CONFIG 1WIRE Befehl überschreibt die Compiler-Einstellungen und sollte bevorzugt werden, da auf diesem Weg die Einstellung im Quellcode gespeichert wird.
<br>The CONFIG 1WIRE statement overrides the compiler setting. It is the preferred that you use it. This way the setting is stored in your source code.
+
Es kann nur ein Pin für 1wire angegeben werden, da mehrere 1-Wire Gräte an einem Bus betrieben werden können.
 
+
You can configure only one pin for the 1WIRE statements because the idea is that you can attach multiple 1WIRE devices to the 1WIRE bus.
+
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
You can however use multiple pins and thus multiple busses. All 1wire commands and functions need the port and pin in that case.
+
Man kann auch mehrere Pins und damit mehrere Busse benutzen. Für diesen Fall benötigen alle 1-Wire Befehle und Funktionen die Angabe des Ports und des Pins.  
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
The 1wire commands and function will automatically set the DDR and PORT register bits to the proper state. You do not need to bring the pins into the right state yourself.
+
Die 1-Wire Kommandos und Funktionen setzen automatisch das Datenrichtungsregister und das Portregister in den richtigen Zustand.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
It is important that you use a pull up resistor of 4K7 ohm on the 1wire pin. The pull up resistor of the AVR is not sufficient.
+
Es ist wichtig, dass am 1-wire-Bus ein Pullup-Widerstand von 4,7 Kiloohm vorhanden ist. Der interne Pullup-Widerstand des AVRs ist nicht geeignet.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
Also notice that some 1wire chips also need +5V. 1 wire is just marketing since you need GND anyway. The least is 2 wires and typical you need 3 wires.
+
Einige 1-Wire-Chips benötigen eine extra 5V-versorgung. 1-Wire ist nur ein Werbe-Begriff, die GND-Leitung wird trotzdem noch benötigt. Das Mindeste sind also 2 Leitungen, typischerweise werden 3 gebraucht.
  
 
&nbsp;
 
&nbsp;

Revision as of 19:03, 1 March 2013

Contents

Funktion

Konfiguriert den Pin zur Benutzung mit 1-Wire und überschreibt die Compiler-Einstellung.

 

 

Syntax

CONFIG 1WIRE = pin [, extended=0|1]

 

 

Beschreibung

Pin

Der Port Pin wie z.B. PORTB.0

extended

Eine optionale Konstante, welche 0 oder 1 sein muss.

 

Der CONFIG 1WIRE Befehl überschreibt die Compiler-Einstellungen und sollte bevorzugt werden, da auf diesem Weg die Einstellung im Quellcode gespeichert wird. Es kann nur ein Pin für 1wire angegeben werden, da mehrere 1-Wire Gräte an einem Bus betrieben werden können.

 

Man kann auch mehrere Pins und damit mehrere Busse benutzen. Für diesen Fall benötigen alle 1-Wire Befehle und Funktionen die Angabe des Ports und des Pins.

 

Die 1-Wire Kommandos und Funktionen setzen automatisch das Datenrichtungsregister und das Portregister in den richtigen Zustand.

 

Es ist wichtig, dass am 1-wire-Bus ein Pullup-Widerstand von 4,7 Kiloohm vorhanden ist. Der interne Pullup-Widerstand des AVRs ist nicht geeignet.

 

Einige 1-Wire-Chips benötigen eine extra 5V-versorgung. 1-Wire ist nur ein Werbe-Begriff, die GND-Leitung wird trotzdem noch benötigt. Das Mindeste sind also 2 Leitungen, typischerweise werden 3 gebraucht.

 

Extended

The extended option is only needed when you use multiple busses/pins and if these are pins mix normal and extended addresses.

Let's clear that up. When the 1wire code was written in 1995 all the port addresses were normal I/O addresses. These are addresses that fit in the I/O space (address < &H60).  To save code, register R31 was cleared in the library and the port register was passed in R30.

When Atmel introduced the extended I/O registers with address >&HFF, it was possible to set R31 to a fixed value when the user port was an extended I/O address.

But when you want to mix the addresses, there is no other way then to pass the word address of the I/O register to the library code.

And that is exactly what EXTENDED=1 will do. It will use more code. This support was written for a customer that already made his PCB's. We do advise to use the same port when you use multiple pins.

 

 

See also

1WRESET , 1WREAD , 1WWRITE , 1WIRECOUNT 1WRESET , 1WSEARCHFIRST , 1WSEARCHNEXT

 

 

Example


'--------------------------------------------------------------------------------
'name : 1wire.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demonstrates 1wreset, 1wwrite and 1wread()
'micro : Mega48
'suited for demo : yes
'commercial addon needed : no
' pull-up of 4K7 required to VCC from Portb.2
' DS2401 serial button connected to Portb.2
'--------------------------------------------------------------------------------
 
$regfile = "m48def.dat"
$crystal = 8000000
 
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 'default use 10 for the SW stack
$framesize = 40 'default use 40 for the frame space
 
 
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
 
'when only bytes are used, use the following lib for smaller code
$lib "mcsbyte.lib"
 
 
Config 1wire = Portb.0 'use this pin
'On the STK200 jumper B.0 must be inserted
Dim Ar(8) As Byte , A As Byte , I As Byte
 
 
Do
Wait 1
1wreset 'reset the device
Print Err 'print error 1 if error
1wwrite &H33 'read ROM command
For I = 1 To 8
 Ar(i) = 1wread() 'place into array
Next
 
'You could also read 8 bytes a time by unremarking the next line
'and by deleting the for next above
'Ar(1) = 1wread(8) 'read 8 bytes
 
For I = 1 To 8
 Print Hex(ar(i)); 'print output
Next
Print 'linefeed
Loop
 
 
'NOTE THAT WHEN YOU COMPILE THIS SAMPLE THE CODE WILL RUN TO THIS POINT
'THIS because of the DO LOOP that is never terminated!!!
 
'New is the possibility to use more than one 1 wire bus
'The following syntax must be used:
For I = 1 To 8
Ar(i) = 0 'clear array to see that it works
Next
 
1wreset Pinb , 2 'use this port and pin for the second device
1wwrite &H33 , 1 , Pinb , 2 'note that now the number of bytes must be specified!
'1wwrite Ar(1) , 5,pinb,2
 
'reading is also different
Ar(1) = 1wread(8 , Pinb , 2) 'read 8 bytes from portB on pin 2
 
For I = 1 To 8
Print Hex(ar(i));
Next
 
'you could create a loop with a variable for the bit number !
For I = 0 To 3 'for pin 0-3
1wreset Pinb , I
1wwrite &H33 , 1 , Pinb , I
Ar(1) = 1wread(8 , Pinb , I)
For A = 1 To 8
 Print Hex(ar(a));
Next
Print
Next
End
 
Xmega Example
'--------------------------------------------------------------------------------
'name : XM128-1wire.bas
'copyright : (c) 1995-2010, MCS Electronics
'purpose : demonstrates 1wreset, 1wwrite and 1wread()
'micro : Xm128A1
'suited for demo : no
'commercial addon needed : no
' pull-up of 4K7 required to VCC from Portb.0
' DS2401 serial button connected to Portb.0
'--------------------------------------------------------------------------------
$regfile = "xm128a1def.dat"
$crystal = 32000000
 
$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
 
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 32 'default use 10 for the SW stack
$framesize = 32 'default use 40 for the frame space
 
'First Enable The Osc Of Your Choice
Config Osc = Enabled , 32mhzosc = Enabled
 
'configure the systemclock
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
 
'configure UART
Config Com1 = 19200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
 
 
'configure 1wire pin
Config 1wire = Portb.0 'use this pin
 
Dim Ar(8) As Byte , A As Byte , I As Byte
 
Print "start"
 
A = 1wirecount()
Print A ; " devices found"
 
'get first
Ar(1) = 1wsearchfirst()
 
For I = 1 To 8 'print the number
Print Hex(ar(i));
Next
Print
 
Do
 'Now search for other devices
 Ar(1) = 1wsearchnext() ' get next device
 For I = 1 To 8
 Print Hex(ar(i));
 Next
 Print
Loop Until Err = 1
 
Waitms 2000
 
 
Do
1wreset 'reset the device
Print Err 'print error 1 if error
 
1wwrite &H33 'read ROM command
' Ar(1) = 1wread(8) you can use this instead of the code below
 
For I = 1 To 8
 Ar(i) = 1wread() 'place into array
Next
 
For I = 1 To 8
 Print Hex(ar(i)); 'print output
Next
Print 'linefeed
Waitms 1000
Loop
 
 
End

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language