Alternative zum DS2423 Counter

Begonnen von dougie, 09 Februar 2013, 16:30:08

Vorheriges Thema - Nächstes Thema

dougie

Poste bitte mal ein Bild der Platinen. Vorder- und Rückseite bitte.

Und wenn du den Kram nicht mehr magst: schick zurück! Ich erstatte dir auch sofort das Geld zurück. Die Platinen sind einwandfrei, das kann ich dir versprechen :-)

Tobias

Eigentlich WILL ich den "Kram" ja zum laufen bekommen ;) Am We lagen die Nerven nur ziemlich blank :(
Ich flashe heute abend dein Hexfile drauf. Wenn es dann immer noch nicht funktioniert mach ich mal von beiden Seiten ein hochauflösendes Foto.
Vielen Dank für deine Unterstützung!!!!!!
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

Tobias

Mit deiner Firmware gehts!!!! :) :) :)

kannst du mir/uns/der Community den Sourcecode bereitstellen? Dazu noch die Info:
- wie (de)aktiviere ich i2C? Also die normalen 2 counter?
- wie ist die Einstellung für i2C auf counter0, normaler counter auf counter1?
- wie ist die Einstellung für i2C auf counter0, der 10sek-Zähler auf counter1?

grüsse
Tobias

Edit: auf beide Platinen hab ich dein hex-file geflashed, und beide Platinen funktionieren (nacheinander) prächtig :) <freu>
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

Tobias

Hi cassi,
ich habe neben C3 einen 33uF Elko eingesetzt, zusätzlich zur batterie. Bei mir leidet der Tiny auch unter Amnesie. Erst das Batteriepack hat funktioniert. Leider in meinen Augen die weniger gute Alternative :(

Nochmal die Bitte den finalen sourcecode hier zu posten, habe die Platinen fertig, nur die Firmware fehlt noch
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

dougie


Tobias,

ich bin schon dabei, das zusammen zu fassen, das man alles auf einem Fleck hat. Den SourceCode findest du z.B. im ersten Beitrag in diesem Thread (oder zumindest den Link dorthin). Die Firmware von Cassy werde ich dazu auch online stellen, aber diese hat aktuell I²C und den Auto-Counter aktiv. Ich wollte noch schauen, ob ich das moduar hin bekomme, aber dafür brauche ich etwas Zeit und Ruhe. Auch eine Anzahl unterscheidlicher HexFiles werde ich alsbald online stellen. Nur hab ich aktuell viel um die Ohren und daher geht's nicht ganz so schnell.

Neue Platinen (V1.6) sind bestellt. Änderungen gegenüber der vorherigen Version ist nur die Möglichkeit einen DS1820 und einen Dual-IO Chip aufzulöten, oder das Battery Pack extern anzuschliessen. Details gibts dazu auch später.

VG
Ralf

Tobias

schade das du schon bestellt hast.
Hätte Änderungswunsch, das man die Notstromspannung mittels Jumper unterbrechen kann für ein kontrolliertes Counter-reset.
Bin auch gerade dabei zu schauen, inwieweit man in der Firmware auf den Spannungsabfall reagieren kann um die Counterstände zu sichern. Ist (für mich) die beste Alternative, heißt aber auch das (wie du vorher schon schriebst) man Vcc auf einen PIN des Tiny legen muss -> Layoutänderung
Allerdings hab ich (noch) von AVR-Programmierung nich-die-Bohne Ahnung

Mein Test gestern hat auch gezeigt, das, zumindest bei mir, die Kombination CR2032+Elko bzgl Notstromversorgung garnichts gebracht hat.
Ich habe leider auch keine äquivalente Batteriehalterung mit Printanschluss mit 3x1,5V gefunden....
Nur soetwas: http://www.voelkner.de/products/156857/Knopfzelle-NiMH-3-6V-120-H-Slf-Emmerich.html
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

Mini-Guido

Hallo,

die zwei fertig aufgebauten Platinen im Gehäuse sind heute auf diese Reise gegangen...
Drei fertige Platinen habe ich noch, allerdings ohne Gehäuse. Falls noch jemand eine möchte, einfach bescheid sagen...

Tobias

Bzgl Stomversorgung in ich etwas weiter, zumindest mit Erkenntnis: einfach VCC auf einen freien Pin zu lenken geht nicht ohne Layoutänderung. Die freien Pins können nicht für einen DauerHIGH benitzt werden, sonst kann man nicht mehr über ISP programmieren. Also müsste man einen Counter von bspw PB3 auf PB1 legen. Allerdings ist noch die Fragfe offen ob der Tiny die Pins auch als AnalogEingänge nutzen kann.

Bin aber zurZEit am schauen ob der Tiny selbst VCC überwachen kann.
Da gibts zum einen die BrownOutDetection. Die muss man nur aktivieren und dann erkennt der Tiny das er kurz vor dem Zusammenbrechen ist, kostet aber permanent ca 20uA Strom.

Bin aber auch auf folgende Seite aufmerksam geworden, bei dem man vcc indirekt messen kann:
ZitatA little known feature of Arduinos and many other AVR chips is the ability to measure the internal 1.1 volt reference. This feature can be exploited to improve the accuracy of the Arduino function  analogRead() when using the default analog reference. It can also be used to measure the Vcc supplied to the AVR chip, which provides a means of monitoring battery voltage without using a precious analog pin to do so.

http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/

Anmerkungen von AVR-Wissenden ist willkommen!
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

dougie


Doch, das geht schon mit dem freien Pin. Du legst diesen über einen 10K Widerstand an die Versorgungsspannung. Da dort eh kein Strom fliesst, hat der Widerstand nur dann eine Funktion, wenn du über ISP programmieren möchtest. Dann wird der 10k einfach ignoriert.
Ich befürchte eine andere Möglichkeit wird es auch nicht geben, weil der Tiny noch einen Moment weiter laufen muss, wenn die 5V 1W Busspannung schon weg sind.

Tobias

Na "diesen Moment weiterlaufen" könnte man IMHO ja mit einem Goldcap lösen..
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

dougie


Völlig richtig, aber so lange dein GoldCap noch Spannung hat, sieht deine interne Referenz kein Problem. Das musst du schon entkoppeln.

dougie


Moin zusammen,

Tobias Müller (der Autor des 1W Tiny25 Codes) hat sich bei mir gemeldet und die angeregte Speicherung ins EEprom bei Spannungsausfall umgesetzt.
Da ich selber gerade keine Platinen mehr habe, konnte ich es nich nicht testen.

Dennoch vorab hier schon mal der SourceCode und die Kommentare von Tobias!

ZitatPB0 (Pin 5) muss direkt an der Betriebsspannung liegen. Allerdings hängt es dann unter umständen ,,in der Luft", wenn die Spannung ausfällt. Vielleicht ist es besser den Eingang mit einer Diode abzukoppeln und danach einen Widertand gegen Masse einzufügen. Ich hänge mal ein Hex-File und den Quellcode rann. Habe es noch nicht abschließend getestet. Stelle es auch demnächst auf die Homepage.

Viele Grüße
Tobias  

Anmerkung: Tobias hat recht, das der PB0 mit einem Widerstand gegen Masse gezogen werden muss. Ich würde als ersten Versuch 47kOhm nehmen. Das belastet den Buss nicht übermässig. Die Diode finde ich auch gut, da man ja nicht genau weiss, was so auf dem Bus im Fehlerfall passiert. Aber auch hier würde ich die BAT43 Schottky Diode nehmen, da sie mit nur 0,3V einen recht niedrigen Spannungsabfall hat.

VG
Ralf

//owdevice - A small 1-Wire emulator for AVR Microcontroller
//
//Copyright (C) 2012  Tobias Mueller mail (at) tobynet.de
//
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
//
//VERSION 1.2 DS2423  for ATTINY2313 and ATTINY25

//FOR MAKE by hand
/*
avr-gcc -mmcu=[attiny25|attiny2313] -O2 -c ow_slave_DS2423.c
avr-gcc.exe -mmcu=[attiny25|attiny2313]  ow_slave_DS2423.o -o ow_slave_DS2423.elf
avr-objcopy -O ihex  ow_slave_DS2423.elf ow_slave_DS2423.hex
*/



#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
//does not work here because less memory by ATtiny13
#if defined(__AVR_ATtiny13A__) || defined(__AVR_ATtiny13__)
// OW_PORT Pin 6  - PB1
//Analog input PB2

//OW Pin
#define OW_PORT PORTB //1 Wire Port
#define OW_PIN PINB //1 Wire Pin as number
#define OW_PORTN (1<<PINB1)  //Pin as bit in registers
#define OW_PINN (1<<PINB1)
#define OW_DDR DDRB  //pin direction register
#define SET_LOW OW_DDR|=OW_PINN;OW_PORT&=~OW_PORTN;  //set 1-Wire line to low
#define RESET_LOW {OW_DDR&=~OW_PINN;}  //set 1-Wire pin as input
//Pin interrupt
#define EN_OWINT {GIMSK|=(1<<INT0);GIFR|=(1<<INTF0);}  //enable interrupt
#define DIS_OWINT  GIMSK&=~(1<<INT0);  //disable interrupt
#define SET_RISING MCUCR=(1<<ISC01)|(1<<ISC00);  //set interrupt at rising edge
#define SET_FALLING MCUCR=(1<<ISC01); //set interrupt at falling edge
#define CHK_INT_EN (GIMSK&(1<<INT0))==(1<<INT0) //test if interrupt enabled
#define PIN_INT ISR(INT0_vect)  // the interrupt service routine
//Timer Interrupt
#define EN_TIMER {TIMSK0 |= (1<<TOIE0); TIFR0|=(1<<TOV0);} //enable timer interrupt
#define DIS_TIMER TIMSK0  &= ~(1<<TOIE0); // disable timer interrupt
#define TCNT_REG TCNT0  //register of timer-counter
#define TIMER_INT ISR(TIM0_OVF_vect) //the timer interrupt service routine

//Initializations of AVR
#define INIT_AVR CLKPR=(1<<CLKPCE);\
  CLKPR=0;/*9.6Mhz*/\
  TIMSK0=0;\
  GIMSK=(1<<INT0);/*set direct GIMSK register*/\
  TCCR0B=(1<<CS00)|(1<<CS01); /*9.6mhz /64 couse 8 bit Timer interrupt every 6,666us*/


//Times
#define OWT_MIN_RESET 51 //minimum duration of the Reset impulse

#define OWT_RESET_PRESENCE 4 //time between rising edge of reset impulse and presence impulse
#define OWT_PRESENCE 20 //duration of the presence impulse
#define OWT_READLINE 4  //duration from master low to read the state of 1-Wire line
#define OWT_LOWTIME 4 //length of low
#endif

#ifdef __AVR_ATtiny25__
// OW_PORT Pin 7  - PB2


//OW Pin
#define OW_PORT PORTB //1 Wire Port
#define OW_PIN PINB //1 Wire Pin as number
#define OW_PORTN (1<<PINB2)  //Pin as bit in registers
#define OW_PINN (1<<PINB2)
#define OW_DDR DDRB  //pin direction register
#define SET_LOW OW_DDR|=OW_PINN;OW_PORT&=~OW_PORTN;  //set 1-Wire line to low
#define RESET_LOW {OW_DDR&=~OW_PINN;}  //set 1-Wire pin as input
//Pin interrupt
#define EN_OWINT {GIMSK|=(1<<INT0);GIFR|=(1<<INTF0);}  //enable interrupt
#define DIS_OWINT  GIMSK&=~(1<<INT0);  //disable interrupt
#define SET_RISING MCUCR=(1<<ISC01)|(1<<ISC00);  //set interrupt at rising edge
#define SET_FALLING MCUCR=(1<<ISC01); //set interrupt at falling edge
#define CHK_INT_EN (GIMSK&(1<<INT0))==(1<<INT0) //test if interrupt enabled
#define PIN_INT ISR(INT0_vect)  // the interrupt service routine
//Timer Interrupt
#define EN_TIMER {TIMSK |= (1<<TOIE0); TIFR|=(1<<TOV0);} //enable timer interrupt
#define DIS_TIMER TIMSK  &= ~(1<<TOIE0); // disable timer interrupt
#define TCNT_REG TCNT0  //register of timer-counter
#define TIMER_INT ISR(TIM0_OVF_vect) //the timer interrupt service routine


#define OWT_MIN_RESET 51
#define OWT_RESET_PRESENCE 4
#define OWT_PRESENCE 20
#define OWT_READLINE 3 //for fast master, 4 for slow master and long lines
#define OWT_LOWTIME 3 //for fast master, 4 for slow master and long lines

//Initializations of AVR
#define INIT_AVR CLKPR=(1<<CLKPCE); \
  CLKPR=0; /*8Mhz*/  \
  TIMSK=0; \
  GIMSK=(1<<INT0);  /*set direct GIMSK register*/ \
  TCCR0B=(1<<CS00)|(1<<CS01); /*8mhz /64 couse 8 bit Timer interrupt every 8us*/\
  Counter0=eeprom_read_dword((const uint32_t *)0);\
  Counter1=eeprom_read_dword((const uint32_t *)4);

 
#define PC_INT_ISR ISR(PCINT0_vect) { /*ATT25 with 0 by PCINT*/ \
if (((PINB&(1<<PINB3))==0)&&((istat&(1<<PINB3))==(1<<PINB3))) { Counter0++; } \
if (((PINB&(1<<PINB4))==0)&&((istat&(1<<PINB4))==(1<<PINB4))) { Counter1++; } \
if (((PINB&(1<<PINB0))==0)&&((istat&(1<<PINB0))==(1<<PINB0))) { \
eeprom_write_dword((const uint32_t *)0,Counter0);\
eeprom_write_dword((const uint32_t *)4,Counter1);  \
} \
istat=PINB;} \

#define INIT_COUNTER_PINS /* Counter Interrupt */\
GIMSK|=(1<<PCIE);\
PCMSK=(1<<PCINT3)|(1<<PCINT4)|(1<<PCINT0);\
DDRB &=~((1<<PINB3)|(1<<PINB4)|(1<<PINB0)); \
istat=PINB;\

 


#endif // __AVR_ATtiny25__

#if defined(__AVR_ATtiny2313A__) || defined(__AVR_ATtiny2313__)
// OW_PORT Pin 6  - PD2


//OW Pin
#define OW_PORT PORTD //1 Wire Port
#define OW_PIN PIND //1 Wire Pin as number
#define OW_PORTN (1<<PIND2)  //Pin as bit in registers
#define OW_PINN (1<<PIND2)
#define OW_DDR DDRD  //pin direction register
#define SET_LOW OW_DDR|=OW_PINN;OW_PORT&=~OW_PORTN;  //set 1-Wire line to low
#define RESET_LOW {OW_DDR&=~OW_PINN;}  //set 1-Wire pin as input
//Pin interrupt
#define EN_OWINT {GIMSK|=(1<<INT0);EIFR|=(1<<INTF0);}  //enable interrupt
#define DIS_OWINT  GIMSK&=~(1<<INT0);  //disable interrupt
#define SET_RISING MCUCR|=(1<<ISC01)|(1<<ISC00);  //set interrupt at rising edge
#define SET_FALLING {MCUCR|=(1<<ISC01);MCUCR&=~(1<<ISC00);} //set interrupt at falling edge
#define CHK_INT_EN (GIMSK&(1<<INT0))==(1<<INT0) //test if interrupt enabled
#define PIN_INT ISR(INT0_vect)  // the interrupt service routine
//Timer Interrupt
#define EN_TIMER {TIMSK |= (1<<TOIE0); TIFR|=(1<<TOV0);} //enable timer interrupt
#define DIS_TIMER TIMSK  &= ~(1<<TOIE0); // disable timer interrupt
#define TCNT_REG TCNT0  //register of timer-counter
#define TIMER_INT ISR(TIMER0_OVF_vect) //the timer interrupt service routine


#define OWT_MIN_RESET 51
#define OWT_RESET_PRESENCE 4
#define OWT_PRESENCE 20
#define OWT_READLINE 3 //for fast master, 4 for slow master and long lines
#define OWT_LOWTIME 3 //for fast master, 4 for slow master and long lines

//Initializations of AVR
#define INIT_AVR CLKPR=(1<<CLKPCE); \
  CLKPR=0; /*8Mhz*/  \
  TIMSK=0; \
  GIMSK=(1<<INT0);  /*set direct GIMSK register*/ \
  TCCR0B=(1<<CS00)|(1<<CS01); /*8mhz /64 couse 8 bit Timer interrupt every 8us*/\
  Counter0=0;\
  Counter1=0;

 
 

#define PC_INT_ISR ISR(PCINT_vect) { /*ATT2313 without 0 by PCINT*/ \
if (((PINB&(1<<PINB3))==0)&&((istat&(1<<PINB3))==(1<<PINB3))) { Counter0++; } \
if (((PINB&(1<<PINB4))==0)&&((istat&(1<<PINB4))==(1<<PINB4))) { Counter1++; } \
istat=PINB;} \

#define INIT_COUNTER_PINS /* Counter Interrupt */\
GIMSK|=(1<<PCIE);\
PCMSK=(1<<PCINT3)|(1<<PCINT4); \
DDRB &=~((1<<PINB3)|(1<<PINB4)); \
istat=PINB;\



#endif // __AVR_ATtiny2313__


//#define _ONE_DEVICE_CMDS_  //Commands for only one device on bus (Not tested)



typedef union {
volatile uint8_t bytes[13];//={1,1,2,0,0,0,0,0,0,0,0,5,5};
struct {
uint16_t addr;
uint8_t read;
uint32_t counter;
uint32_t zero;
uint16_t crc;
};
} counterpack_t;
counterpack_t counterpack;
volatile uint16_t scrc; //CRC calculation

volatile uint8_t lastcps;
volatile uint32_t Counter0;
volatile uint32_t Counter1;
volatile uint8_t istat;


volatile uint8_t cbuf; //Input buffer for a command
const uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x02, 0x37};    
//set your own ID http://www.tm3d.de/index.php/tools/14-crc8-berechnung
volatile uint8_t bitp;  //pointer to current Byte
volatile uint8_t bytep; //pointer to current Bit

volatile uint8_t mode; //state
volatile uint8_t wmode; //if 0 next bit that send the device is  0
volatile uint8_t actbit; //current
volatile uint8_t srcount; //counter for search rom

//States / Modes
#define OWM_SLEEP 0  //Waiting for next reset pulse
#define OWM_RESET 1  //Reset pulse received
#define OWM_PRESENCE 2  //sending presence pulse
#define OWM_READ_COMMAND 3 //read 8 bit of command
#define OWM_SEARCH_ROM 4  //SEARCH_ROM algorithms
#define OWM_MATCH_ROM 5  //test number
#define OWM_CHK_RESET 8  //waiting of rising edge from reset pulse
#define OWM_GET_ADRESS 6
#define OWM_READ_MEMORY_COUNTER 7
#define OWM_WRITE_SCRATCHPAD 9
#define OWM_READ_SCRATCHPAD 10

#ifdef _ONE_DEVICE_CMDS_
#define OWM_READ_ROM 50
#endif

//Write a bit after next falling edge from master
//its for sending a zero as soon as possible
#define OWW_NO_WRITE 2
#define OWW_WRITE_1 1
#define OWW_WRITE_0 0



PIN_INT {
uint8_t lwmode=wmode;  //let this variables in registers
uint8_t lmode=mode;
if ((lwmode==OWW_WRITE_0)) {SET_LOW;lwmode=OWW_NO_WRITE;}    //if necessary set 0-Bit
DIS_OWINT; //disable interrupt, only in OWM_SLEEP mode it is active
switch (lmode) {
case OWM_SLEEP:  
TCNT_REG=~(OWT_MIN_RESET);
EN_OWINT; //other edges ?
break;
//start of reading with falling edge from master, reading closed in timer isr
case OWM_MATCH_ROM:  //falling edge wait for receive
case OWM_GET_ADRESS:
case OWM_READ_COMMAND:
TCNT_REG=~(OWT_READLINE); //wait a time for reading
break;
case OWM_SEARCH_ROM:   //Search algorithm waiting for receive or send
if (srcount<2) { //this means bit or complement is writing,
TCNT_REG=~(OWT_LOWTIME);
} else
TCNT_REG=~(OWT_READLINE);  //init for read answer of master
break;
#ifdef _ONE_DEVICE_CMDS_
case OWM_READ_ROM:
#endif
case OWM_READ_MEMORY_COUNTER: //a bit is sending
TCNT_REG=~(OWT_LOWTIME);
break;
case OWM_CHK_RESET:  //rising edge of reset pulse
SET_FALLING;
TCNT_REG=~(OWT_RESET_PRESENCE);  //waiting for sending presence pulse
lmode=OWM_RESET;
break;
}
EN_TIMER;
mode=lmode;
wmode=lwmode;

}



TIMER_INT {
uint8_t lwmode=wmode; //let this variables in registers
uint8_t lmode=mode;
uint8_t lbytep=bytep;
uint8_t lbitp=bitp;
uint8_t lsrcount=srcount;
uint8_t lactbit=actbit;
uint16_t lscrc=scrc;
//Ask input line sate
uint8_t p=((OW_PIN&OW_PINN)==OW_PINN);  
//Interrupt still active ?
if (CHK_INT_EN) {
//maybe reset pulse
if (p==0) {
lmode=OWM_CHK_RESET;  //wait for rising edge
SET_RISING;
}
DIS_TIMER;
} else
switch (lmode) {
case OWM_RESET:  //Reset pulse and time after is finished, now go in presence state
lmode=OWM_PRESENCE;
SET_LOW;
TCNT_REG=~(OWT_PRESENCE);
DIS_OWINT;  //No Pin interrupt necessary only wait for presence is done
break;
case OWM_PRESENCE:
RESET_LOW;  //Presence is done now wait for a command
lmode=OWM_READ_COMMAND;
cbuf=0;lbitp=1;  //Command buffer have to set zero, only set bits will write in
break;
case OWM_READ_COMMAND:
if (p) {  //Set bit if line high
cbuf|=lbitp;
}
lbitp=(lbitp<<1);
if (!lbitp) { //8-Bits read
lbitp=1;
switch (cbuf) {
case 0x55:lbytep=0;lmode=OWM_MATCH_ROM;break;
case 0xF0:  //initialize search rom
lmode=OWM_SEARCH_ROM;
lsrcount=0;
lbytep=0;
lactbit=(owid[lbytep]&lbitp)==lbitp; //set actual bit
lwmode=lactbit;  //prepare for writing when next falling edge
break;
case 0xA5:
lmode=OWM_GET_ADRESS; //first the master send an address
lbytep=0;lscrc=0x7bc0; //CRC16 of 0xA5
counterpack.bytes[0]=0;
break;
#ifdef _ONE_DEVICE_CMDS_
case 0xCC:
lbytep=0;cbuf=0;lmode=OWM_READ_COMMAND;break;
case 0x33:
lmode=OWM_READ_ROM;
lbytep=0;
break;
#endif
default: lmode=OWM_SLEEP;  //all other commands do nothing
}
}
break;
case OWM_SEARCH_ROM:
RESET_LOW;  //Set low also if nothing send (branch takes time and memory)
lsrcount++;  //next search rom mode
switch (lsrcount) {
case 1:lwmode=!lactbit;  //preparation sending complement
break;
case 3:
if (p!=(lactbit==1)) {  //check master bit
lmode=OWM_SLEEP;  //not the same go sleep
} else {
lbitp=(lbitp<<1);  //prepare next bit
if (lbitp==0) {
lbitp=1;
lbytep++;
if (lbytep>=8) {
lmode=OWM_SLEEP;  //all bits processed
break;
}
}
lsrcount=0;
lactbit=(owid[lbytep]&lbitp)==lbitp;
lwmode=lactbit;
}
break;
}
break;
case OWM_MATCH_ROM:
if (p==((owid[lbytep]&lbitp)==lbitp)) {  //Compare with ID Buffer
lbitp=(lbitp<<1);
if (!lbitp) {
lbytep++;
lbitp=1;
if (lbytep>=8) {
lmode=OWM_READ_COMMAND;  //same? get next command

cbuf=0;
break;
}
}
} else {
lmode=OWM_SLEEP;
}
break;
case OWM_GET_ADRESS:  
if (p) { //Get the Address for reading
counterpack.bytes[lbytep]|=lbitp;
}  
//address is part of crc
if ((lscrc&1)!=p) lscrc=(lscrc>>1)^0xA001; else lscrc >>=1;
lbitp=(lbitp<<1);
if (!lbitp) {
lbytep++;
lbitp=1;
if (lbytep==2) {
lmode=OWM_READ_MEMORY_COUNTER;
lactbit=(lbitp&counterpack.bytes[lbytep])==lbitp;
lwmode=lactbit;
lsrcount=(counterpack.addr&0xfe0)+0x20-counterpack.addr;
//bytes between start and Counter Values, Iam never understanding why so much???
break;
} else counterpack.bytes[lbytep]=0;
}
break;
case OWM_READ_MEMORY_COUNTER:
RESET_LOW;
//CRC16 Calculation
if ((lscrc&1)!=lactbit) lscrc=(lscrc>>1)^0xA001; else lscrc >>=1;
p=lactbit;
lbitp=(lbitp<<1);
if (!lbitp) {
lbytep++;
lbitp=1;
if (lbytep==3) {
lsrcount--;
if (lsrcount) lbytep--;
else  {//now copy counter in send buffer
switch (counterpack.addr&0xFe0) {
case 0x1E0:
counterpack.counter=Counter0;
break;
case 0x1C0:
counterpack.counter=Counter1;
break;
default: counterpack.counter=0;
}
}
}
if (lbytep>=13) { //done sending
lmode=OWM_SLEEP;
break;
}  
if ((lbytep==11)&&(lbitp==1)) { //Send CRC
counterpack.crc=~lscrc;
}

}
lactbit=(lbitp&counterpack.bytes[lbytep])==lbitp;
lwmode=lactbit;

break;
#ifdef _ONE_DEVICE_CMDS_
case OWM_READ_ROM:
RESET_LOW;
lbitp=(lbitp<<1);
if (!lbitp) {
lbytep++;
lbitp=1;
if (lbytep>=8) {
lmode=OWM_SLEEP;
break;
}
}
lactbit=(lbitp&owid[lbytep])==lbitp;
lwmode=lactbit;
break;
#endif
}
if (lmode==OWM_SLEEP) {DIS_TIMER;}
if (lmode!=OWM_PRESENCE)  {
TCNT_REG=~(OWT_MIN_RESET-OWT_READLINE);  //OWT_READLINE around OWT_LOWTIME
EN_OWINT;
}
mode=lmode;
wmode=lwmode;
bytep=lbytep;
bitp=lbitp;
srcount=lsrcount;
actbit=lactbit;
scrc=lscrc;
}



PC_INT_ISR  //for counting  defined for specific device



int main(void) {
mode=OWM_SLEEP;
wmode=OWW_NO_WRITE;
OW_DDR&=~OW_PINN;

uint8_t i;
for(i=0;i<sizeof(counterpack);i++) counterpack.bytes[i]=0;


SET_FALLING;

INIT_AVR
DIS_TIMER;

INIT_COUNTER_PINS

sei();

while(1){

}
}

Tobias

Hi Ralf,
kannst du den SourceCode mal bitte als Datei hier posten? Ich bekomme (vieleicht deshalb??)folgende Fehler beim compilieren:
root@laptop:/home/tobias/Downloads# avr-gcc -mmcu=attiny25 -O2 -c ow_slave_DS2423.c
ow_slave_DS2423.c: In function '__vector_2':
ow_slave_DS2423.c:496:1: warning: passing argument 1 of '__eewr_dword_tn25' discards qualifiers from pointer target type
/usr/lib/gcc/avr/4.5.3/../../../avr/include/avr/eeprom.h:552:1: note: expected 'uint32_t *' but argument is of type 'const uint32_t *'
ow_slave_DS2423.c:496:1: warning: passing argument 1 of '__eewr_dword_tn25' discards qualifiers from pointer target type
/usr/lib/gcc/avr/4.5.3/../../../avr/include/avr/eeprom.h:552:1: note: expected 'uint32_t *' but argument is of type 'const uint32_t *'
root@laptop:/home/tobias/Downloads#

Edit: habe die "const" entfernt und nun compilierts.

Für alle anderen, mit folgendem Code kann mans gut compilieren, die Inline-Doku ist nicht ganz korrekt, da gabs bei mir fehler:
root@laptop:/home/tobias/Downloads# avr-gcc -mmcu=attiny25 -O2 -o ow_slave_DS2423.o ow_slave_DS2423.c
root@laptop:/home/tobias/Downloads# avr-objcopy -O ihex  ow_slave_DS2423.o ow_slave_DS2423.hex
root@laptop:/home/tobias/Downloads# avrdude -p ATTiny25 -c stk500v2 -P /dev/ttyUSB1 -U flash:w:ow_slave_DS2423.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9108
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "ow_slave_DS2423.hex"
avrdude: input file ow_slave_DS2423.hex auto detected as Intel Hex
avrdude: writing flash (1556 bytes):

Writing | ################################################## | 100% 0.87s

avrdude: 1556 bytes of flash written
avrdude: verifying flash memory against ow_slave_DS2423.hex:
avrdude: load data flash data from input file ow_slave_DS2423.hex:
avrdude: input file ow_slave_DS2423.hex auto detected as Intel Hex
avrdude: input file ow_slave_DS2423.hex contains 1556 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.70s

avrdude: verifying ...
avrdude: 1556 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

root@laptop:/home/tobias/Downloads#


Btw: mittels owhttpd kontrolliert, die counter sind gut voll ;) Kann man die resetten? Also einmalig 0 ins eeprom schreiben?

counters.ALL 4294967295, 4294967295
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

Tobias

Nur zum Verständnis:
Statt CR2032 einen Goldcap benutzen, die D2 Diode weglassen damit der Goldcap sich aufladen kann.
Dann PB0 mit einer Diode nach Vcc sowie mit 47K gegen Gnd. Kann man als Diode auch eine N4148 nehmen?

Was mir noch unklar ist, durch den Goldcap wird die Spannung einen Moment aufrecht erhalten. Wie erkennt nun der Tiny das die Spannung vom Goldcap kommt? Fällt in dem Fall die Spannung kontinuierlich ab und ab einem bestimmten Schwellwert greift die "ins-eeprom-schreiben" Routine?
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

dougie

Fast.

GoldCap anstelle der Batterie ist richtig. Diode vor dem GoldCap durch ne Drahtbrücke ersetzen, aber dafür die 5V vom 1W Bus über eine Diode führen und dann Bussseitig die 5V messen.
Ich mach nen neuen Schaltplan, sobald ich etwas Zeit finde.