<div dir="ltr"><div>Len pre info - 1-wire sa da urobit aj bez presnych cakaciek. To sa moze hodit vtedy, ak clovek presne cakacky nemoze pouzit, trebars kvoli tomu, ze je treba obsluhovat nejaky rychly interrupt (alebo skratka nechce "zabijat cas"). Pouziva sa tam USART, ak sa k tomu doda nejaky timer, da sa 1-wire master urobit plne "interrupt-driven".<br>
<a href="http://www.maximintegrated.com/app-notes/index.mvp/id/214">http://www.maximintegrated.com/app-notes/index.mvp/id/214</a><br></div>Dnes, ked je na kde-akom MCU nejaky USART nazvys, sa to moze hodit.<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2014-01-27 Marek Sembol <span dir="ltr"><<a href="mailto:hwm.land@gmail.com" target="_blank">hwm.land@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Dekuji, to mi bude rozhodne stacit. V podstate klicove je<div class="im"><div><span style="font-family:arial,sans-serif;font-size:13px">static void __INLINE DelayUs(uint16_t us)</span><br style="font-family:arial,sans-serif;font-size:13px">

<span style="font-family:arial,sans-serif;font-size:13px">{</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">    uint16_t cnts = DS_TIMER->CNT;</span><br style="font-family:arial,sans-serif;font-size:13px">

<span style="font-family:arial,sans-serif;font-size:13px">    while ((uint16_t)(DS_TIMER->CNT - cnts) < us);</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">}</span><br>

</div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div><span style="font-family:arial,sans-serif;font-size:13px">Nedoslo mi jak jednoduse ty us cekacky udelat. Mrknu rad i na zbytek, dik</span></div>
<span class="HOEnZb"><font color="#888888">
<div><span style="font-family:arial,sans-serif;font-size:13px">Marek</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">
On Mon, Jan 27, 2014 at 7:45 PM, Jaroslav Buchta <span dir="ltr"><<a href="mailto:jaroslav.buchta@hascomp.cz" target="_blank">jaroslav.buchta@hascomp.cz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div>Ja to implementoval na STM32, klicove
      je casovani tech kratkych intervalu desitek us, ja to delal
      prostrednictvim casovace. Samozrejme je problem vyuzivat nejaka
      preruseni behem techto kritickych useku, pro UART pouzivam DMA,
      FreeRTOS ma blokovana preruseni.<br>
      Pro inspiraci zdrojak (neni jeste nejak ucesany):<br>
      <br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      #include "main.h"<br>
      #include <string.h><br>
      #include "DS1820.h"<br>
      <br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      #define OW_ONE_BUS<br>
      #define OW_OPENCOLL<br>
      <br>
      #define DS_PERIPHIO RCC_APB2Periph_GPIOB<br>
      #define DS_PORT     GPIOB<br>
      #define DS_PIN_I1    GPIO_Pin_6<br>
      #define DS_PIN_O1    GPIO_Pin_7<br>
      #define DS_PIN_I2    GPIO_Pin_8<br>
      #define DS_PIN_O2    GPIO_Pin_9<br>
      #define DS_PERIPHTM RCC_APB1Periph_TIM2<br>
      #define DS_TIMER    TIM2<br>
      <br>
      <br>
      <br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      #define CRC8INIT    0x00<br>
      #define CRC8POLY    0x18              //0X18 = X^8+X^5+X^4+X^0<br>
      <br>
      uint8_t    crc8 ( uint8_t *data_in, uint8_t
      number_of_bytes_to_read )<br>
      {<br>
          uint8_t    crc;<br>
          uint8_t     loop_count;<br>
          uint8_t      bit_counter;<br>
          uint8_t      data;<br>
          uint8_t      feedback_bit;<br>
      <br>
          crc = CRC8INIT;<br>
      <br>
          for (loop_count = 0; loop_count != number_of_bytes_to_read;
      loop_count++)<br>
          {<br>
              data = data_in[loop_count];<br>
              bit_counter = 8;<br>
              do<br>
              {<br>
                  feedback_bit = (crc ^ data) & 0x01;<br>
      <br>
                  if ( feedback_bit == 0x01 )<br>
                  {<br>
                      crc = crc ^ CRC8POLY;<br>
                  }<br>
                  crc = (crc >> 1) & 0x7F;<br>
                  if ( feedback_bit == 0x01 )<br>
                  {<br>
                      crc = crc | 0x80;<br>
                  }<br>
      <br>
                  data = data >> 1;<br>
                  bit_counter--;<br>
      <br>
              }<br>
              while (bit_counter > 0);<br>
          }<br>
      <br>
          return crc;<br>
      }<br>
      <br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      void ow_Init()<br>
      {<br>
          // Init port pins<br>
          RCC_APB2PeriphClockCmd(DS_PERIPHIO, ENABLE);<br>
          GPIO_SetBits(DS_PORT, DS_PIN_O1 | DS_PIN_O2);<br>
          GPIO_InitTypeDef iodef_i = {DS_PIN_I1 | DS_PIN_I2,
      GPIO_Speed_10MHz, GPIO_Mode_IPU};<br>
          GPIO_Init(DS_PORT, &iodef_i);<br>
          GPIO_InitTypeDef iodef_o = {DS_PIN_O1 | DS_PIN_O2,
      GPIO_Speed_10MHz, GPIO_Mode_Out_PP};<br>
          GPIO_Init(DS_PORT, &iodef_o);<br>
      <br>
          // Init timer<br>
          /* Compute the prescaler value */<br>
          uint16_t PrescalerValue = (uint16_t) (SystemCoreClock /
      1000000UL) - 1;<br>
      <br>
          TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;<br>
          /* Time base configuration */<br>
          RCC_APB1PeriphClockCmd(DS_PERIPHTM, ENABLE);<br>
          TIM_TimeBaseStructure.TIM_Period = 65535;<br>
          TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;<br>
          TIM_TimeBaseStructure.TIM_ClockDivision = 0;<br>
          TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;<br>
          TIM_TimeBaseInit(DS_TIMER, &TIM_TimeBaseStructure);<br>
          TIM_Cmd(DS_TIMER, ENABLE);<br>
      }<br>
      <br>
      <br>
      static void __INLINE DelayUs(uint16_t us)<br>
      {<br>
          uint16_t cnts = DS_TIMER->CNT;<br>
          while ((uint16_t)(DS_TIMER->CNT - cnts) < us);<br>
      }<br>
      <br>
      /*******************************************/<br>
      <br>
      #define OW_MATCH_ROM    0x55<br>
      #define OW_SKIP_ROM        0xCC<br>
      #define    OW_SEARCH_ROM    0xF0<br>
      <br>
      <br>
      <br>
      <br>
      <br>
      uint8_t ow_reset(uint8_t devId)<br>
      {<br>
          uint16_t err;<br>
          uint16_t pinO = devId == 0 ? DS_PIN_O1 : DS_PIN_O2;<br>
          uint16_t pinI = devId == 0 ? DS_PIN_I1 : DS_PIN_I2;<br>
      <br>
          DS_PORT->BRR = pinO;<br>
          DelayUs(500);<br>
          DS_PORT->BSRR = pinO;<br>
          __disable_irq();<br>
          DelayUs(66);<br>
          err = DS_PORT->IDR & pinI;            // no presence
      detect<br>
          __enable_irq();<br>
          DelayUs(480-66);<br>
          if( (DS_PORT->IDR & pinI) == 0 )    // short circuit<br>
              err = 1;<br>
      <br>
          return err;<br>
      }<br>
      <br>
      /* Timing issue when using runtime-bus-selection (!OW_ONE_BUS):<br>
         The master should sample at the end of the 15-slot after
      initiating<br>
         the read-time-slot. The variable bus-settings need more<br>
         cycles than the constant ones so the delays had to be shortened<br>
         to achive a 15uS overall delay<br>
         Setting/clearing a bit in I/O Register needs 1 cyle in
      OW_ONE_BUS<br>
         but around 14 cyles in configureable bus (us-Delay is 4 cyles
      per uS) */<br>
      uint8_t ow_bit_io( uint8_t b, uint8_t devId)<br>
      {<br>
             uint16_t pinO = devId == 0 ? DS_PIN_O1 : DS_PIN_O2;<br>
          uint16_t pinI = devId == 0 ? DS_PIN_I1 : DS_PIN_I2;<br>
          __disable_irq();<br>
          DS_PORT->BRR = pinO;<br>
          DelayUs(2); // Recovery-Time wuffwuff was 1<br>
          if ( b )<br>
          {<br>
              DS_PORT->BSRR = pinO;<br>
          }<br>
          // wuffwuff delay was 15uS-1 see comment above<br>
          DelayUs(15-2);<br>
          if((DS_PORT->IDR & pinI) == 0) b = 0;  // sample at end
      of read-timeslot<br>
          DelayUs(60-15-2);<br>
          DS_PORT->BSRR = pinO;<br>
          __enable_irq();<br>
          DelayUs(15);<br>
          return b;<br>
      }<br>
      <br>
      <br>
      uint8_t ow_byte_wr( uint8_t b, uint8_t devId)<br>
      {<br>
          uint8_t i = 8, j;<br>
      <br>
          do {<br>
              j = ow_bit_io( b & 1, devId);<br>
              b >>= 1;<br>
              if( j ) b |= 0x80;<br>
          } while( --i );<br>
      <br>
          return b;<br>
      }<br>
      <br>
      <br>
      uint8_t ow_byte_rd(uint8_t devId)<br>
      {<br>
        // read by sending 0xff (a dontcare?)<br>
        return ow_byte_wr(0xFF, devId);<br>
      }<br>
      <br>
      <br>
      uint8_t ow_rom_search( uint8_t diff, uint8_t* id, uint8_t devId)<br>
      {<br>
          uint8_t i, j, next_diff;<br>
          uint8_t b;<br>
      <br>
      DS_PORT->BRR = DS_PIN_O2;<br>
          if( ow_reset(devId) ) return OW_PRESENCE_ERR;    // error, no
      device found<br>
      DS_PORT->BSRR = DS_PIN_O2;<br>
      <br>
          ow_byte_wr( OW_SEARCH_ROM, devId );            // ROM search
      command<br>
          next_diff = OW_LAST_DEVICE;            // unchanged on last
      device<br>
      <br>
          i = OW_ROMCODE_SIZE * 8;                    // 8 bytes<br>
      <br>
          do<br>
          {<br>
              j = 8;                    // 8 bits<br>
              do<br>
              {<br>
                  b = ow_bit_io( 1, devId );            // read bit<br>
                  if( ow_bit_io( 1, devId ) )<br>
                  {                            // read complement bit<br>
                      if( b )                    // 11<br>
                      return OW_DATA_ERR;            // data error<br>
                  }<br>
                  else<br>
                  {<br>
                      if( !b ) {                // 00 = 2 devices<br>
                          if( diff > i || ((*id & 1) &&
      diff != i) )<br>
                          {<br>
                              b = 1;                // now 1<br>
                              next_diff = i;        // next pass 0<br>
                          }<br>
                      }<br>
                  }<br>
                  ow_bit_io( b, devId );                 // write bit<br>
                  *id >>= 1;<br>
                  if( b ) *id |= 0x80;            // store bit<br>
      <br>
                  i--;<br>
      <br>
              } while( --j );<br>
      <br>
              id++;                    // next uint8_t<br>
      <br>
          } while( i );<br>
      <br>
          return next_diff;                // to continue search<br>
      }<br>
      <br>
      <br>
      void ow_command( uint8_t command, uint8_t *id, uint8_t devId)<br>
      {<br>
          uint8_t i;<br>
      <br>
          ow_reset(devId);<br>
      <br>
          if( id )<br>
          {<br>
              ow_byte_wr( OW_MATCH_ROM, devId);            // to a
      single device<br>
              i = OW_ROMCODE_SIZE;<br>
              do<br>
              {<br>
                  ow_byte_wr( *id, devId);<br>
                  id++;<br>
              } while( --i );<br>
          }<br>
          else<br>
          {<br>
              ow_byte_wr( OW_SKIP_ROM, devId);            // to all
      devices<br>
          }<br>
      <br>
          ow_byte_wr( command, devId);<br>
      }<br>
      <br>
      <br>
      <br>
/////////////////////////////////////////////////////////////////////////////<br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      /* return values */<br>
      #define DS18X20_OK          0x00<br>
      #define DS18X20_ERROR       0x01<br>
      #define DS18X20_START_FAIL  0x02<br>
      #define DS18X20_ERROR_CRC   0x03<br>
      <br>
      #define DS18X20_POWER_PARASITE 0x00<br>
      #define DS18X20_POWER_EXTERN   0x01<br>
      <br>
      /* DS18X20 specific values (see datasheet) */<br>
      #define DS18S20_ID 0x10<br>
      #define DS18B20_ID 0x28<br>
      <br>
      #define DS18X20_CONVERT_T    0x44<br>
      #define DS18X20_READ        0xBE<br>
      #define DS18X20_WRITE        0x4E<br>
      #define DS18X20_EE_WRITE    0x48<br>
      #define DS18X20_EE_RECALL    0xB8<br>
      #define DS18X20_READ_POWER_SUPPLY 0xB4<br>
      <br>
      #define DS18B20_CONF_REG    4<br>
      #define DS18B20_9_BIT       0<br>
      #define DS18B20_10_BIT      (1<<5)<br>
      #define DS18B20_11_BIT      (1<<6)<br>
      #define DS18B20_12_BIT      ((1<<6)|(1<<5))<br>
      <br>
      // indefined bits in LSB if 18B20 != 12bit<br>
      #define DS18B20_9_BIT_UNDF      
      ((1<<0)|(1<<1)|(1<<2))<br>
      #define DS18B20_10_BIT_UNDF      ((1<<0)|(1<<1))<br>
      #define DS18B20_11_BIT_UNDF      ((1<<0))<br>
      #define DS18B20_12_BIT_UNDF      0<br>
      <br>
      // conversion times in ms<br>
      #define DS18B20_TCONV_12BIT      750<br>
      #define DS18B20_TCONV_11BIT      DS18B20_TCONV_12BIT/2<br>
      #define DS18B20_TCONV_10BIT      DS18B20_TCONV_12BIT/4<br>
      #define DS18B20_TCONV_9BIT       DS18B20_TCONV_12BIT/8<br>
      #define DS18S20_TCONV            DS18B20_TCONV_12BIT<br>
      <br>
      // constant to convert the fraction bits to cel*(10^-4)<br>
      #define DS18X20_FRACCONV         625<br>
      <br>
      #define DS18X20_SP_SIZE  9<br>
      <br>
      // DS18X20 EEPROM-Support<br>
      #define DS18X20_WRITE_SCRATCHPAD  0x4E<br>
      #define DS18X20_COPY_SCRATCHPAD   0x48<br>
      #define DS18X20_RECALL_E2         0xB8<br>
      #define DS18X20_COPYSP_DELAY      10 /* ms */<br>
      #define DS18X20_TH_REG      2<br>
      #define DS18X20_TL_REG      3<br>
      <br>
      <br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      /* find DS18X20 Sensors on 1-Wire-Bus<br>
         input/ouput: diff is the result of the last rom-search<br>
         output: id is the rom-code of the sensor found */<br>
      void DS18X20_find_sensor(uint8_t *diff, uint8_t *id, uint8_t
      devId)<br>
      {<br>
          for (;;)<br>
          {<br>
              *diff = ow_rom_search( *diff, &id[0], devId);<br>
              if ( *diff==OW_PRESENCE_ERR || *diff==OW_DATA_ERR ||<br>
                *diff == OW_LAST_DEVICE ) return;<br>
              if ( id[0] == DS18B20_ID || id[0] == DS18S20_ID ) return;<br>
          }<br>
      }<br>
      <br>
      /* get power status of DS18x20<br>
         input  : id = rom_code<br>
         returns: DS18X20_POWER_EXTERN or DS18X20_POWER_PARASITE */<br>
      uint8_t    DS18X20_get_power_status(uint8_t *id, uint8_t devId)<br>
      {<br>
          uint8_t pstat;<br>
          ow_reset(devId);<br>
          ow_command(DS18X20_READ_POWER_SUPPLY, id, devId);<br>
          pstat=ow_bit_io(1, devId); // pstat 0=is parasite/ !=0 ext.
      powered<br>
          ow_reset(devId);<br>
          return (pstat) ? DS18X20_POWER_EXTERN:DS18X20_POWER_PARASITE;<br>
      }<br>
      <br>
      /* start measurement (CONVERT_T) for all sensors if input id==NULL<br>
         or for single sensor. then id is the rom-code */<br>
      uint8_t DS18X20_start_meas(uint8_t *id, uint8_t devId)<br>
      {<br>
          if (ow_reset(devId))<br>
              return DS18X20_ERROR; //**<br>
          ow_command( DS18X20_CONVERT_T, id, devId);<br>
          return DS18X20_OK;<br>
      }<br>
      <br>
      /* reads temperature (scratchpad) of sensor with rom-code id<br>
         output: subzero==1 if temp.<0, cel: full celsius, mcel: frac<br>
         in millicelsius*0.1<br>
         i.e.: subzero=1, cel=18, millicel=5000 = -18,5000°C */<br>
      uint8_t DS18X20_read_meas(uint8_t *id, uint16_t *tempRaw, uint8_t
      devId)<br>
      {<br>
          uint8_t i;<br>
          uint8_t sp[DS18X20_SP_SIZE];<br>
          uint16_t meas;<br>
      <br>
          if (ow_reset(devId))<br>
              return DS18X20_ERROR; //**<br>
          ow_command(DS18X20_READ, id, devId);<br>
          for ( i=0 ; i< DS18X20_SP_SIZE; i++ )
      sp[i]=ow_byte_rd(devId);<br>
          if ( crc8( &sp[0], DS18X20_SP_SIZE ) )<br>
              return DS18X20_ERROR_CRC;<br>
      <br>
          meas = sp[0];  // LSB<br>
          meas |= ((uint16_t)sp[1])<<8; // MSB<br>
          //meas = 0xff5e; meas = 0xfe6f;<br>
      <br>
          //  only work on 12bit-base<br>
          if( id[0] == DS18S20_ID )<br>
          { // 9 -> 12 bit if 18S20<br>
              /* Extended measurements for DS18S20 contributed by
      Carsten Foss */<br>
              meas &= (uint16_t) 0xfffe;    // Discard LSB , needed
      for later extended precicion calc<br>
              meas <<= 3;                    // Convert to 12-bit
      , now degrees are in 1/16 degrees units<br>
      //        meas += (16 - sp[6]) - 4;    // Add the compensation ,
      and remember to subtract 0.25 degree (4/16)<br>
              meas += 16*((uint16_t)sp[7] -
      (uint16_t)sp[6])/(uint16_t)sp[7] - 4;    // Add the compensation ,
      and remember to subtract 0.25 degree (4/16)<br>
          }<br>
          else<br>
          {<br>
              meas = 0;        // unsupported now<br>
          }<br>
      <br>
          *tempRaw = meas;<br>
          return DS18X20_OK;<br>
      }<br>
      <br>
      /*<br>
      #ifdef DS18X20_EEPROMSUPPORT<br>
      <br>
      uint8_t DS18X20_write_scratchpad( uint8_t id[],<br>
          uint8_t th, uint8_t tl, uint8_t conf)<br>
      {<br>
          ow_reset(); //<br>
          if( ow_input_pin_state() ) { // only send if bus is "idle" =
      high<br>
              ow_command( DS18X20_WRITE_SCRATCHPAD, id );<br>
              ow_byte_wr(th);<br>
              ow_byte_wr(tl);<br>
              if (id[0] == DS18B20_ID) ow_byte_wr(conf); // config
      avail. on B20 only<br>
              return DS18X20_OK;<br>
          }<br>
          else {<br>
              #ifdef DS18X20_VERBOSE<br>
              uart_puts_P( "DS18X20_write_scratchpad: Short Circuit
      !\r\n" );<br>
              #endif<br>
              return DS18X20_ERROR;<br>
          }<br>
      }<br>
      <br>
      uint8_t DS18X20_read_scratchpad( uint8_t id[], uint8_t sp[] )<br>
      {<br>
          uint8_t i;<br>
      <br>
          ow_reset(); //<br>
          if( ow_input_pin_state() ) { // only send if bus is "idle" =
      high<br>
              ow_command( DS18X20_READ, id );<br>
              for ( i=0 ; i< DS18X20_SP_SIZE; i++ )   
      sp[i]=ow_byte_rd();<br>
              return DS18X20_OK;<br>
          }<br>
          else {<br>
              #ifdef DS18X20_VERBOSE<br>
              uart_puts_P( "DS18X20_read_scratchpad: Short Circuit
      !\r\n" );<br>
              #endif<br>
              return DS18X20_ERROR;<br>
          }<br>
      }<br>
      <br>
      uint8_t DS18X20_copy_scratchpad( uint8_t with_power_extern,<br>
          uint8_t id[] )<br>
      {<br>
          ow_reset(); //<br>
          if( ow_input_pin_state() ) { // only send if bus is "idle" =
      high<br>
              ow_command( DS18X20_COPY_SCRATCHPAD, id );<br>
              if (with_power_extern != DS18X20_POWER_EXTERN)<br>
                  ow_parasite_enable();<br>
              delay_ms(DS18X20_COPYSP_DELAY); // wait for 10 ms<br>
              if (with_power_extern != DS18X20_POWER_EXTERN)<br>
                  ow_parasite_disable();<br>
              return DS18X20_OK;<br>
          }<br>
          else {<br>
              #ifdef DS18X20_VERBOSE<br>
              uart_puts_P( "DS18X20_copy_scratchpad: Short Circuit
      !\r\n" );<br>
              #endif<br>
              return DS18X20_START_FAIL;<br>
          }<br>
      }<br>
      <br>
      uint8_t DS18X20_recall_E2( uint8_t id[] )<br>
      {<br>
          ow_reset(); //<br>
          if( ow_input_pin_state() ) { // only send if bus is "idle" =
      high<br>
              ow_command( DS18X20_RECALL_E2, id );<br>
              // TODO: wait until status is "1" (then eeprom values<br>
              // have been copied). here simple delay to avoid timeout<br>
              // handling<br>
              delay_ms(DS18X20_COPYSP_DELAY);<br>
              return DS18X20_OK;<br>
          }<br>
          else {<br>
              #ifdef DS18X20_VERBOSE<br>
              uart_puts_P( "DS18X20_recall_E2: Short Circuit !\r\n" );<br>
              #endif<br>
              return DS18X20_ERROR;<br>
          }<br>
      }<br>
      #endif<br>
      */<br>
      <br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
///////////////////////////////////////////////////////////////////////////////<br>
      DS18X20_DESC    DsTSensDesc1[OW_MAX_DEVICES];<br>
      DS18X20_DESC    DsTSensDesc2[OW_MAX_DEVICES];<br>
      uint8_t            DsTSensCount1;<br>
      uint8_t            DsTSensCount2;<br>
      <br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      void TSens_Init()<br>
      {<br>
          ow_Init();<br>
          memset(DsTSensDesc1, 0x00, sizeof(DsTSensDesc1));<br>
          memset(DsTSensDesc2, 0x00, sizeof(DsTSensDesc2));<br>
          DsTSensCount1 = 0;<br>
          DsTSensCount2 = 0;<br>
      }<br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      uint8_t TSens_ScanForDevices(uint8_t devId)<br>
      {<br>
          uint8_t b;<br>
          uint8_t id[OW_ROMCODE_SIZE];<br>
      <br>
          b = ow_reset(devId);<br>
          if (b) return TSENS_ERR_HW;<br>
      <br>
          b = OW_SEARCH_FIRST;<br>
      <br>
          if (devId== 0)<br>
          {<br>
              DsTSensCount1 = 0;<br>
              memset(DsTSensDesc1, 0x00, sizeof(DsTSensDesc1));<br>
      <br>
              while (DsTSensCount1 < OW_MAX_DEVICES)<br>
              {<br>
                  DS18X20_find_sensor(&b, id, devId);<br>
                  if (b == OW_PRESENCE_ERR) return TSENS_ERR_HW;<br>
                  if (b == OW_DATA_ERR) return TSENS_ERR_DATA;<br>
      <br>
                  PDS18X20_DESC pd = &DsTSensDesc1[DsTSensCount1++];<br>
                  memcpy(pd->id, id, OW_ROMCODE_SIZE);<br>
                  pd->status = TSENS_ERR_VOID;<br>
                  if (b == OW_LAST_DEVICE) break;<br>
              }<br>
          }<br>
          else<br>
          {<br>
              DsTSensCount2 = 0;<br>
              memset(DsTSensDesc2, 0x00, sizeof(DsTSensDesc2));<br>
      <br>
              while (DsTSensCount2 < OW_MAX_DEVICES)<br>
              {<br>
                  DS18X20_find_sensor(&b, id, devId);<br>
                  if (b == OW_PRESENCE_ERR) return TSENS_ERR_HW;<br>
                  if (b == OW_DATA_ERR) return TSENS_ERR_DATA;<br>
      <br>
                  PDS18X20_DESC pd = &DsTSensDesc2[DsTSensCount2++];<br>
                  memcpy(pd->id, id, OW_ROMCODE_SIZE);<br>
                  pd->status = TSENS_ERR_VOID;<br>
                  if (b == OW_LAST_DEVICE) break;<br>
              }<br>
          }<br>
          return TSENS_ERR_OK;<br>
      }<br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      uint8_t *TSens_GetCntPtr(uint8_t devId)<br>
      {<br>
          if (devId== 0)     return &DsTSensCount1;<br>
          return &DsTSensCount2;<br>
      }<br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      PDS18X20_DESC TSens_GetConfPtr(uint8_t idx, uint8_t devId)<br>
      {<br>
          if (devId == 0) return DsTSensDesc1+idx;<br>
          return DsTSensDesc2+idx;<br>
      }<br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      static int8_t  nDevIdx = -2;<br>
      static uint32_t wStartTicks = 0;<br>
      <br>
      int TSens_SrvFunc (uint8_t devId)<br>
      {<br>
          uint8_t bRes = DS18X20_OK;<br>
          PDS18X20_DESC pd = DsTSensDesc1;<br>
          uint8_t cnt = DsTSensCount1;<br>
          if (devId != 0)<br>
          {<br>
              pd = DsTSensDesc2;<br>
              cnt = DsTSensCount2;<br>
          }<br>
          if (nDevIdx == -2)<br>
          {<br>
              bRes = DS18X20_start_meas(NULL, devId);<br>
              wStartTicks = GetTickCount();<br>
              if (bRes != DS18X20_OK)<br>
              {<br>
                  uint8_t idx;<br>
      <br>
                  for (idx=0; idx<cnt; idx++)<br>
                  {<br>
                      pd++->status = TSENS_ERR_HW;<br>
                  }<br>
              }<br>
              else<br>
              {<br>
                  nDevIdx = -1;<br>
              }<br>
          }<br>
          else if (nDevIdx == -1)<br>
          {<br>
              if (GetTickCount() - wStartTicks > DS18S20_TCONV)
      nDevIdx = 0;<br>
          }<br>
          else if (nDevIdx < cnt)<br>
          {<br>
              bRes = DS18X20_read_meas(pd->id, &pd->tempRaw,
      devId);<br>
              if (bRes == DS18X20_OK)<br>
              {<br>
                  pd->status = TSENS_ERR_OK;<br>
              }<br>
              else<br>
              {<br>
                  pd->status = TSENS_ERR_HW;<br>
              }<br>
              nDevIdx++;<br>
          }<br>
          else<br>
          {<br>
              nDevIdx = -2;<br>
          }<br>
          return bRes == DS18X20_OK ? 1 : 0;<br>
      }<br>
      <br>
      <br>
///////////////////////////////////////////////////////////////////////////////<br>
      <br>
      <br>
      <br>
      <br>
      Dne 27.1.2014 19:39, Marek Sembol napsal(a):<br>
    </div>
    <blockquote type="cite"><div>
      <div dir="ltr">Nemate nekdo odzkousenou implementaci 1-wire pro
        LPC1xxx?
        <div>Marek</div>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      </div><pre>_______________________________________________
HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" target="_blank">www.HW.cz</a>
<a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a>
<a href="http://list.hw.cz/mailman/listinfo/hw-list" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a>
</pre>
    </blockquote>
    <br>
  
<br><br>
<hr style="border:none;color:#909090;background-color:#b0b0b0;min-height:1px;width:99%">
<table style="border-collapse:collapse;border:none">
        <tbody><tr>
                <td style="border:none;padding:0px 15px 0px 8px">
                        <a href="http://www.avast.com/" target="_blank">
                                <img src="http://static.avast.com/emails/avast-mail-stamp.png" border="0">
                        </a>
                </td>
                <td>
                        <p style="color:#3d4d5a;font-family:"Calibri","Verdana","Arial","Helvetica";font-size:12pt">
                                Tato zpráva neobsahuje viry ani jiný ¹kodlivý kód -<a href="http://www.avast.com/" target="_blank">avast! Antivirus</a> je aktivní.
                        </p>
                </td>
        </tr>
</tbody></table>
<br>
</div>

<br>_______________________________________________<br>
HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" target="_blank">www.HW.cz</a><br>
<a href="mailto:Hw-list@list.hw.cz" target="_blank">Hw-list@list.hw.cz</a><br>
<a href="http://list.hw.cz/mailman/listinfo/hw-list" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
HW-list mailing list  -  sponsored by <a href="http://www.HW.cz" target="_blank">www.HW.cz</a><br>
<a href="mailto:Hw-list@list.hw.cz">Hw-list@list.hw.cz</a><br>
<a href="http://list.hw.cz/mailman/listinfo/hw-list" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
<br></blockquote></div><br></div>