<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=7669&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-07-06T00:31:24+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=7669&amp;mode</id>
<entry>
<author><name><![CDATA[luqasz1]]></name></author>
<updated>2014-07-06T00:31:24+01:00</updated>
<published>2014-07-06T00:31:24+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86711#p86711</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86711#p86711"/>
<title type="html"><![CDATA[Re: DS18B20 zapis ID czujnika do EEPROM]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86711#p86711"><![CDATA[
Zrobiłem na bibliotece Mirka i jest to samo. Tak jakby tablica struktura.term1 była pusta. Zmieniłem char term1 na uint8_t term1 w strzukturze i też nie działa. Wydaje mi się, że jednak błąd może być w funkcji zapisującej i odczytującej. Proszę o pomoc, jeśli potrzebujecie dodatkowych informacji to proszę pytać.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3880">luqasz1</a> — 6 lip 2014, o 00:31</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[luqasz1]]></name></author>
<updated>2014-07-05T11:14:10+01:00</updated>
<published>2014-07-05T11:14:10+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86655#p86655</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86655#p86655"/>
<title type="html"><![CDATA[Re: DS18B20 zapis ID czujnika do EEPROM]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86655#p86655"><![CDATA[
To jest biblioteka, której używam. Dodam, że mam dwa czujniki działające w trybie parasite. Tak sobie myślę, że może w tablicy term[] wcale nie znajdują się identyfikatory, chociaż wtedy nie powinno działać odczytywanie temperatury.<br /><br /><div class="quotetitle">xpower napisał(a):</div><div class="quotecontent"><br />najpierw kopiowałem te ID do struktury ram, a dopiero cała strukturę ram zapisywałem do eeprom.<br /></div><br />No i ja też tak robię (co widać w kodzie), tylko korzystam z innej biblioteki i nie mogę sobie poradzić.<br /><br />[syntax=c]#include&lt;util/delay.h&gt;<br />#ifndef ONE_WIRE_H<br />#define ONE_WIRE_H<br />#define PRZERWANIA_ON<br />#ifdef PRZERWANIA_ON<br />#include&lt;avr/interrupt.h&gt;<br />#endif<br /><br />#define NULL 0<br /><br />#define   wire_1()  W_DDR&amp;=~_BV(W_BIT)<br />#define   wire_0()  W_DDR|=_BV(W_BIT)<br />#define   wire()    bit_is_set(W_PIN,W_BIT)<br /><br />#define ERROR_CRC 175<br />// 1 Wire Commands<br /><br />#define CONVERT_T 0x44<br />#define READ_SCRATCHPAD 0xBE<br />#define WRITE_SCRATCHPAD 0x4E<br />#define COPY_SCRATCHPAD 0x48<br />#define RECALL_E2 0xB8<br />#define READ_POWER_SUPPLY 0xB4<br /><br />#define SKIP_ROM  0xCC<br />#define SEARCH_ROM 0xF0<br />#define READ_ROM 0x33<br />#define MATCH_ROM 0x55<br />#define ALARM_SEARCH 0xEC<br /><br />/* Return codes for OWFirst()/OWNext() */<br />#define OW_BADWIRE8<br />#define OW_BADCRC4<br />#define OW_NOPRESENCE2<br />#define OW_NOMODULES0<br />#define OW_FOUND1<br /><br /><br />#define BIT_9  0x1F<br />#define BIT_10  0x3F<br />#define BIT_11  0x5F<br />#define BIT_12  0x7F<br />/*deklaracje zmiennych*/<br />static uint8_t OW_LastDevice = 0;<br />static uint8_t OW_LastDiscrepancy = 0;<br />static uint8_t OW_LastFamilyDiscrepancy = 0;<br />/*deklaracje funkcji*/<br />static uint8_t OWFirst(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only);<br />static uint8_t OWNext(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only);<br />static void OWSendCmd(uint8_t *ROM, uint8_t cmd);<br /><br />uint8_t wire_reset(void)<br />{<br />  uint8_t ack;<br />  wire_0();<br />  _delay_us(600);<br />  wire_1();<br />  _delay_us(100);<br />  ack=wire();<br />  _delay_us(500);<br />  return ack;<br />}<br /><br />void wire_send_bit(uint8_t bit)<br />{<br />#ifdef PRZERWANIA_ON<br /><br />  uint8_t sreg=SREG;<br />  cli();<br />#endif<br />  wire_0();<br />  _delay_us(10);<br />  if(bit)<br />    {<br />      wire_1();<br />      _delay_us(60);<br />    }<br />  else<br />    {<br />      _delay_us(80);<br />      wire_1();<br />    }<br />  _delay_us(5);<br />#ifdef PRZERWANIA_ON<br />  SREG=sreg;<br />#endif<br />}<br /><br />uint8_t wire_receive_bit(void)<br />{<br />#ifdef PRZERWANIA_ON<br />  uint8_t sreg=SREG;<br />  cli();<br />#endif<br />  uint8_t bit;<br />  wire_0();<br />  _delay_us(5);<br />  wire_1();<br />  _delay_us(10);<br />  bit=wire();<br />  //while(!wire()){};<br />  _delay_us(50);<br />#ifdef PRZERWANIA_ON<br />  SREG=sreg;<br />#endif<br />  return (bit?1:0);<br />}<br /><br />void wire_write_byte(uint8_t command)<br /> {<br />    for (uint8_t i = 0; i &lt; 8; i++)<br />     {<br />         wire_send_bit(command &amp; 0x01);<br />         command &gt;&gt;= 1; //shift to next bit<br />     }<br /> }<br /><br />uint8_t wire_read_byte(void)<br /> {<br />    uint8_t i, result = 0;<br />    for (i = 0; i &lt; 8; i++)<br />      {<br />        result &gt;&gt;= 1;<br />        if (wire_receive_bit())result |= 0x80;<br />      }<br />    return(result);<br />  }<br /><br />static void wire_init(uint8_t* adr,uint8_t rozdz,uint8_t tmin,uint8_t tmax)<br />{<br />  OWSendCmd(adr,WRITE_SCRATCHPAD);<br />  wire_write_byte(tmax);<br />  wire_write_byte(tmin);<br />  wire_write_byte(rozdz);<br />  OWSendCmd(adr,COPY_SCRATCHPAD);<br />  _delay_ms(10);<br />}<br /><br /><br />/*********************************************************************************************<br /> *  Function name : OW_ComputeCRC8<br /> *<br /> *  Purpose :Compute the CRC8 value of a data set.<br /> *     This function will compute the CRC8 or DOW-CRC of inData using seed<br /> *       as inital value for the CRC.<br /> *<br /> *  Parameters: inData  One byte of data to compute CRC from.<br /> *<br /> *   seed    The starting value of the CRC.<br /> *<br /> *  Return: The CRC8 of inData with seed as initial value.<br /> *<br /> *  Note:   Setting seed to 0 computes the crc8 of the inData.<br /> *          Constantly passing the return value of this function<br /> *          As the seed argument computes the CRC8 value of a<br /> *          longer string of data.<br /> ************************************************************************************************ */<br />unsigned char wire_compute_CRC8(unsigned char inData, unsigned char seed)<br />{<br />    unsigned char bitsLeft;<br />    unsigned char temp;<br /><br />    for (bitsLeft = 8; bitsLeft &gt; 0; bitsLeft--)<br />    {<br />        temp = ((seed ^ inData) &amp; 0x01);<br />        if (temp == 0)<br />        {<br />            seed &gt;&gt;= 1;<br />        }<br />        else<br />        {<br />            seed ^= 0x18;<br />            seed &gt;&gt;= 1;<br />            seed |= 0x80;<br />        }<br />        inData &gt;&gt;= 1;<br />    }<br />    return seed;<br />}<br />/*-----------------------------------------------------------------------------<br /> * Send a 1 wire command to a device, or all if no ROM ID provided<br /> */<br />static void OWSendCmd(uint8_t *ROM, uint8_t cmd)<br />{<br />  uint8_ti;<br />  wire_reset();<br />wire_write_byte(MATCH_ROM);<br />for (i = 0; i &lt; 8; i++)<br />    wire_write_byte(ROM&#91;i&#93;);<br /><br />  wire_write_byte(cmd);<br />}<br />/*-----------------------------------------------------------------------------<br /> * Search algorithm from App note 187 (and 162)<br /> *<br /> * OWFirst/OWNext return..<br /> *         1 when something is found,<br /> *         0 no more modules<br /> *   -1 if no presense pulse,<br /> *         -2 if bad CRC,<br /> *         -3 if bad wiring.<br /> */<br />static uint8_t OWFirst(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only)<br />{<br />    /* Reset state */<br />    OW_LastDiscrepancy = 0;<br />    OW_LastDevice = 0;<br />    OW_LastFamilyDiscrepancy = 0;<br /><br />    /* Go looking */<br />    return (OWNext(ROM, do_reset, alarm_only));<br />}<br /><br />/* Returns 1 when something is found, 0 if nothing left */<br />static uint8_t OWNext(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only)<br />{<br />    uint8_tbit_test, search_direction, bit_number;<br />    uint8_tlast_zero, rom_byte_number, rom_byte_mask;<br />    uint8_tlastcrc8, crcaccum;<br />    int8_tnext_result;<br /><br />    /* Init for search */<br />   bit_number = 1;<br />   last_zero = 0;<br />   rom_byte_number = 0;<br />   rom_byte_mask = 1;<br />   next_result = OW_NOMODULES;<br />   lastcrc8 = 0;<br />   crcaccum = 0;<br /><br />   /* if the last call was not the last one */<br />   if (!OW_LastDevice)<br />    {<br />      /* check if reset first is requested */<br />      if (do_reset)<br />        {<br />          /* reset the 1-wire * if there are no parts on 1-wire, return 0 */<br />         if (wire_reset())<br />          {<br />            /* reset the search */<br />          OW_LastDiscrepancy = 0;<br />          OW_LastFamilyDiscrepancy = 0;<br />          return OW_NOPRESENCE;<br />          }<br />       }<br /><br />      /* If finding alarming devices issue a different command */<br />      if (alarm_only)<br />       wire_write_byte(ALARM_SEARCH);/* issue the alarming search command */<br />    else<br />       wire_write_byte(SEARCH_ROM);/* issue the search command */<br />      /* pause before beginning the search */<br />      _delay_us(210);<br />      /* loop to do the search */<br />      do<br />        {<br />         /* read a bit and its compliment */<br />         bit_test = wire_receive_bit() &lt;&lt; 1;<br />         bit_test |= wire_receive_bit();<br />           /* check for no devices on 1-wire */<br />         if (bit_test == 3)<br />            {<br />              return(OW_BADWIRE);<br />          }<br />         else<br />            {<br />             /* all devices coupled have 0 or 1 */<br />             if (bit_test &gt; 0)<br />              search_direction = !(bit_test &amp; 0x01);  /* bit write value for search */<br />             else<br />                {<br />              /* if this discrepancy is before the Last Discrepancy<br />                   * on a previous OWNext then pick the same as last time */<br />              if (bit_number &lt; OW_LastDiscrepancy)<br />                  search_direction = ((ROM&#91;rom_byte_number&#93; &amp; rom_byte_mask) &gt; 0);<br />              else<br />                  /* if equal to last pick 1, if not then pick 0 */<br />                search_direction = (bit_number == OW_LastDiscrepancy);<br />                  /* if 0 was picked then record its position in LastZero */<br />              if (search_direction == 0)<br />                    {<br />                  last_zero = bit_number;<br />                  /* check for Last discrepancy in family */<br />                  if (last_zero &lt; 9)<br />                   OW_LastFamilyDiscrepancy = last_zero;<br />                }<br />              }<br />             /* set or clear the bit in the ROM byte rom_byte_number<br />               * with mask rom_byte_mask */<br />             if (search_direction == 1)<br />              ROM&#91;rom_byte_number&#93; |= rom_byte_mask;<br />             else<br />              ROM&#91;rom_byte_number&#93; &amp;= ~rom_byte_mask;<br />                /* serial number search direction write bit */<br />             wire_send_bit(search_direction);<br />                /* increment the byte counter bit_number<br />               * and shift the mask rom_byte_mask */<br />             bit_number++;<br />             rom_byte_mask &lt;&lt;= 1;<br />              /* if the mask is 0 then go to new ROM byte rom_byte_number<br />               * and reset mask */<br />             if (rom_byte_mask == 0)<br />                {<br />              crcaccum=wire_compute_CRC8(ROM&#91;rom_byte_number&#93;,crcaccum);  /* accumulate the CRC */<br />              lastcrc8 = crcaccum;<br />              rom_byte_number++;<br />              rom_byte_mask = 1;<br />              }<br />          }<br />        } while (rom_byte_number &lt; 8);  /* loop until through all ROM bytes 0-7 */<br />      /* if the search was successful then */<br />      if (!(bit_number &lt; 65) || lastcrc8)<br />        {<br />        if (lastcrc8)<br />            {<br />             next_result = OW_BADCRC;<br />            }<br />          else<br />            {<br />              /*  search successful so set LastDiscrepancy,LastDevice,next_result */<br />              OW_LastDiscrepancy = last_zero;<br />              OW_LastDevice = (OW_LastDiscrepancy == 0);<br />              next_result = OW_FOUND;<br />            }<br />        }<br />    }<br />   /* if no device found then reset counters so next 'next' will be<br />    * like a first */<br />   if (next_result != OW_FOUND || ROM&#91;0&#93; == 0)<br />    {<br />      OW_LastDiscrepancy = 0;<br />      OW_LastDevice = 0;<br />      OW_LastFamilyDiscrepancy = 0;<br />    }<br />   if (next_result == OW_FOUND &amp;&amp; ROM&#91;0&#93; == 0x00)<br />       next_result = OW_BADWIRE;<br /><br />   return next_result;<br />}<br /><br /><br />#endif[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3880">luqasz1</a> — 5 lip 2014, o 11:14</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[xpower]]></name></author>
<updated>2014-07-05T09:59:03+01:00</updated>
<published>2014-07-05T09:59:03+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86648#p86648</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86648#p86648"/>
<title type="html"><![CDATA[Re: DS18B20 zapis ID czujnika do EEPROM]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86648#p86648"><![CDATA[
Hmm jakoś dziwnie mi się patrzy na ten kod, jakby w niektórych miejscach brakowało przecinków <img src="https://forum.atnel.pl/images/smilies/icon_razz.gif" alt=":P" title="Pokazuje język" /> Ale może tylko mi się wydaje.<br /><br />Jeśli korzystasz z bibliotek 1wire dołączonych do BlueBook'a to tam masz tablice, która przechowuje ID czujników dostępnych na linii.<br />[syntax=c]uint8_t gSensorIDs&#91;MAXSENSORS&#93;&#91;OW_ROMCODE_SIZE&#93;[/syntax]<br /><br />Wystarczy przekopiować zawartość tablicy odpowiadającej danemu czujnikowi bajt po bajcie. Przynajmniej ja to kiedyś tak rozwiązałem i z powodzeniem działało, chociaż najpierw kopiowałem te ID do struktury ram, a dopiero cała strukturę ram zapisywałem do eeprom.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=607">xpower</a> — 5 lip 2014, o 09:59</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[luqasz1]]></name></author>
<updated>2014-07-05T00:36:53+01:00</updated>
<published>2014-07-05T00:36:53+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86631#p86631</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86631#p86631"/>
<title type="html"><![CDATA[DS18B20 zapis ID czujnika do EEPROM]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=7669&amp;p=86631#p86631"><![CDATA[
[syntax=c]char term&#91;2&#93;&#91;8&#93;;<br />typedef struct<br />{<br />    uint8_t high_temp;<br />    uint8_t histereza;<br />    uint8_t temp_zal_pompy;<br />    char term1&#91;8&#93;;<br />    //char term2&#91;8&#93;;<br />} ST;<br />ST EEMEM EEStruct;<br />ST struktura;<br /><br />void WriteStructureToEeprom(ST a)<br />{<br />   eeprom_write_block((const void*)&amp;a, (void*)&amp;EEStruct, sizeof(ST));<br />}<br /><br />ST ReadStructureFromEeprom(void){<br />   ST temp;<br />   eeprom_read_block((void*)&amp;temp, (const void*)&amp;EEStruct, sizeof(ST));<br />   return(temp);<br />}<br /><br />OWFirst(term&#91;0&#93;,1,0);<br />OWNext(term&#91;1&#93;,1,0);<br />wire_reset();<br /><br />// kilka linijek kodu dalej...<br /><br />struktura.high_temp=80;<br />struktura.histereza=3;<br />struktura.temp_zal_pompy=28;<br />memcpy(struktura.term1, term&#91;0&#93;,8);<br /><br />WriteStructureToEeprom(struktura);[/syntax]<br /><br />Witam,<br />Procesor, który programuję to ATMega8. Na tym forum znalazłem funkcje do zapisywania struktury do EEPROMu napisane przez użytkownika Sunriver i o ile uważam, że działają one dobrze to mam problem z zapisaniem ID czujnika do pamięci EEPROM. Wszystkie inne dane struktury zapisują się poprawnie, tylko właśnie char term1 jest pusty. Próbowałem różnych sposobów przez 2 dni i skończyły mi się pomysły. Dodam jeszcze, że jeśli wypełnię tablicę term[0] liczbami i literami to bez problemu da się zapisać to do pamięci EEPROM. Problem tylko jest wtedy gdy w tej tablicy znajduje się ID czujnika. <br />Proszę o pomoc w rozwiązaniu problemu.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3880">luqasz1</a> — 5 lip 2014, o 00:36</p><hr />
]]></content>
</entry>
</feed>