View previous topic :: View next topic |
Author |
Message |
pavelustinov
Joined: 09 Mar 2013 Posts: 20
|
ds1820_read problem |
Posted: Sat Mar 09, 2013 2:43 pm |
|
|
Hello!
I try code from first reply:
http://www.ccsinfo.com/forum/viewtopic.php?t=28425
It compiles successfully.
But it’s a strange problem with ds1820_read() function.
Code: | lcd_putc("\f1234");// print
delay_ms(400);
temperature = ds1820_read();
lcd_putc("\f5678");// NEVER print
delay_ms(400); |
LCD prints 1234, but 5678 – never print.
ds1820_read() function like stop the program.
P.S.
I found this infinite loop.
Code: | while (busy == 0)
busy = onewire_read(); |
This function
Code: | int onewire_read()
{
int count, data;
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 ); // pull 1-wire low to initiate read time-slot.
output_float(ONE_WIRE_PIN); // now let 1-wire float high,
delay_us( 8 ); // let device state stabilise,
shift_right(&data,1,input(ONE_WIRE_PIN)); // and load result.
delay_us( 120 ); // wait until end of read slot.
}
return( data );
} |
I don't know why always return the wrong value. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Sun Mar 10, 2013 5:24 am |
|
|
It's not seeing the device. It waits for the device to return some data. It's seeing 'ONE_WIRE_PIN' as permanently low.
Have you got the pin definition right to match your device?.
The code further down the thread is slightly 'improved' (gives the full resolution), but this should work OK, if the hardware is OK.
Best Wishes |
|
|
|