From 8afa3e3f9de66d6ae11fc1a0ca839be31c327631 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Sat, 3 Aug 2013 04:45:35 +0000 Subject: ds18x20 onewire temp sensor example git-svn-id: https://svn.spreadspace.org/avr/trunk@210 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-1wire/usb-1wire.c | 226 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 197 insertions(+), 29 deletions(-) (limited to 'usb-1wire/usb-1wire.c') diff --git a/usb-1wire/usb-1wire.c b/usb-1wire/usb-1wire.c index a383ef1..6fed4f5 100644 --- a/usb-1wire/usb-1wire.c +++ b/usb-1wire/usb-1wire.c @@ -1,8 +1,10 @@ /* - * spreadspace avr utils + * spreadspace avr utils - usb-1wire example * * - * Copyright (C) 2013 Christian Pointner + * Copyright (C) 2013 Bernhard Tittelbach + * basically this is refactored and enhanced code from: + * http://www.pjrc.com/teensy/td_libs_OneWire.html * * This file is part of spreadspace avr utils. * @@ -24,45 +26,211 @@ #include #include #include -#include +#include #include #include "util.h" #include "led.h" #include "usbio.h" +#include "onewire.h" + +#define MAX_OWI_DEVICES 3 + +uint8_t owi_addr_[MAX_OWI_DEVICES][8]; +uint8_t num_owi_dev_found_; + +void discoverOWIBus(void) +{ + uint8_t d=0; + led_on(); + + printf("Searching OW Bus "); + num_owi_dev_found_ = 0; + if (owi_reset()) + printf(" !something is there! "); + owi_reset_search(); + _delay_ms(250); + + //Search only for DS1820 temp sensors + owi_target_search(DS1820_FAMILY_ID); + + while ( owi_search(owi_addr_[ d ])) + { + d++; + printf("%d. found, ", d); + led_toggle(); + if ( d >= MAX_OWI_DEVICES) + break; + } + num_owi_dev_found_ = d; + printf(" done \r\n"); + printf("%d devices found\r\n", d); + + for (d=0; d 0) { - int ReceivedByte = fgetc(stdin); - if(ReceivedByte != EOF) { - handle_cmd(ReceivedByte); - } - BytesReceived--; - } + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + cpu_init(); + led_init(); + usbio_init(); + sei(); + DDRC &= ~7; + owi_init(7, &PINC); + + for(;;) + { + int16_t BytesReceived = usbio_bytes_received(); + while(BytesReceived > 0) + { + int ReceivedByte = fgetc(stdin); + if(ReceivedByte != EOF) { + handle_cmd(ReceivedByte); + } + BytesReceived--; + } usbio_task(); - } + } } -- cgit v1.2.3