DS18B20 an PIC12F1572 liefert nur 255,255

Gast #5325658
Lesenswert?

Hallo Leute,

Habe folgendes Problem:
Will bei einen DS1820 per Mikrobasic Pro auslesen.
Leider bekomme ich in den zwei Bytes immer nur 255 retour.

Was ich schon versucht habe:
Anderen DS18B20
DS18B20 an Klemmen
Pullup variiert. (1k,1k2,1k8,2k2,3k3,4k7)
Anderen PIC12F1572

Was funktioniert:
5V am DS18B20 sind stabil
PIC läuft und LED blinkt
UART Läuft und sendet die RICHTIGEN Daten der Temp Variable
1 Wire Library an EasyPIC7 mit DS18B20 und PIC18F45K22 getestet

Configuration:
500khz interner Takt
MCLR dekativiert. Ist IO.
Watchdog ist ein.

Programm:
1
program DS18B20_Test
2

3
dim LED as sbit at RA4_Bit
4
dim OneWire as sbit at RA5_Bit
5

6
sub procedure InitHardware
7
    PORTA = %00000000         'Reset all IO bits
8
    TRISA  = %00101010        'Select inputs/outputs
9
    SLRCONA = %00000000       'Disable slewrate limit
10
    'TRISA.0  = 0             'RA0 = Output = TX
11
    'TRISA.1  = 1             'RA1 = Input = RX
12
    'TRISA.2  = 0             'RA2 = Output = Reserved
13
    'TRISA.3  = 1             'RA3 = Input = Reserved
14
    'TRISA.4  = 0             'RA4 = Output = LED
15
    'TRISA.5  = 1             'RA5 = Input = 1 Wire
16
    'TRISA.6  = 0             'Not implemented
17
    'TRISA.7  = 0             'Not implemented
18
    ANSELA  = %00000000       'All pins are digital
19
end sub
20

21
sub procedure ReadTemperature
22
    dim temp as byte
23
    Ow_Reset(PortA, 5)        'Reset Onewire
24
    Ow_Write(PortA, 5, 0xCC)  'Send SKIP_ROM
25
    Ow_Write(PortA, 5, 0x44)  'Send CONVERT_T
26
    Delay_ms(750)             'Wait 750ms for conversion end
27
    Ow_Reset(PortA, 5)        'Reset Onewire
28
    Ow_Write(PortA, 5, 0xCC)  'Send SKIP_ROM
29
    Ow_Write(PortA, 5, 0xBE)  'Send READ_SCRATCHPAD
30
    temp = Ow_Read(PortA, 5)  'Read first byte
31
    UART1_Write(temp)         'Write to UART
32
    temp = Ow_Read(PortA, 5)  'Read second byte
33
    UART1_Write(temp)         'Write to UART
34
end sub
35

36
main:
37
     InitHardware             'Setup the hardware
38
     UART1_Init(19200)        'Setup the UART
39
     while 1                  'Mainloop
40
           clrwdt             'Clear watchdog timer
41
           LED = LED xor 1    'Toggle LED
42
           delay_ms(250)      'Wait 1 second (~750ms from DS18B20)
43
           ReadTemperature    'Read temperature
44
     wend
45
end.

Habt Ihr noch eine Idee?
Bin schon beim verzweifeln.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren