<?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=7262&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-06-01T22:30:52+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=7262&amp;mode</id>
<entry>
<author><name><![CDATA[Micron]]></name></author>
<updated>2014-06-01T22:30:52+01:00</updated>
<published>2014-06-01T22:30:52+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=83001#p83001</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=83001#p83001"/>
<title type="html"><![CDATA[Re: Wire.endTransmission w języku c...]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=83001#p83001"><![CDATA[
Ok zamykam.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1189">Micron</a> — 1 cze 2014, o 22:30</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2014-06-01T22:13:38+01:00</updated>
<published>2014-06-01T22:13:38+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=83000#p83000</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=83000#p83000"/>
<title type="html"><![CDATA[Re: Wire.endTransmission w języku c...]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=83000#p83000"><![CDATA[
No to teraz kolega mnie zaskoczył na maxa .... myślałem że chodzi o coś niezwykle nietypowego - ...... o jakąś specyficzną funkcję <strong><span style="color: #0040FF">endTransmission()</span></strong> ..... do jakiegoś tam urządzenia ... nie wiem jakiego - i nie wnikam <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> .... dlatego prosiłem ew o kod źródłowy arduino żeby coś podpowiedzieć .....<br /><br />zaglądam ci ja sobie do tej biblioteki a tu co ? standardowa biblioteka jakaś do komunikacji I2C .... funkcja (metoda klasy) o której mówisz to dokładnie ta:<br /><br /><br />[syntax=c]uint8_t TwoWire::endTransmission(uint8_t sendStop) {<br />  // transmit buffer (blocking)<br />  int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1, sendStop);<br />  // reset tx buffer iterator vars<br />  txBufferIndex = 0;<br />  txBufferLength = 0;<br />  // indicate that we are done transmitting<br />  transmitting = 0;<br />  return ret;<br />}[/syntax]<br /><br />a tu tymczasem &quot;extra&quot; pytanie do całości <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> <br /><br /><div class="quotetitle">Micron napisał(a):</div><div class="quotecontent"><br />Nie działa mi to za dobrze, gdzie mogę mieć błąd?<br /></div><br /><br />No to w czym problem ? czy myślisz że ktoś kto to przeczytał wie o co tobie chodzi w ogóle? o jakie niedziałanie? <br /><br />- nie działa koledze to w arduino ? czy chodzi o to że nie działa ta funkcja ? czy chodzi o to że przerabiasz sobie całość na C i nie działa ci TYLKO ta funkcja ? czy jak ? ..... sorki ale to masakra <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> .... może jednak warto czasem zadawać bardziej precyzyjnie pytania ? nie sądzisz ? ..... w ten sposób to można w kalambury grać tak w nieskończoność<br /><br />Bo skąd ja mam wiedzieć gdzie ty możesz mieć jakiś błąd w arduino skoro jak mówiłem nie używam arduino <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /> to po pierwsze<br /><br />Po drugie - nawet gdyby miał ktoś pomóc kto zna arduino to chyba wypadałoby DOKŁADNIE opisać ten cały błąd - pokazać też swój kod jak to używasz czy jak ? ..... A nie pisać - <br /><br /><div class="quotetitle"><b>Quote:</b></div><div class="quotecontent"><br />&quot;nie działa mi to, możecie mi powiedzieć gdzie robię błąd?&quot;<br /></div><br /><br />no panie kolego .... panie kolego<br /><br />Jeśli zaś przerabiasz np to już z arduino na C (czego też jakoś wyraźnie nie napisałeś) ... to też - co ci nie działa ? jak przerobiłeś inne funkcje ? inne ci działają ? <br /><br />Wyżej pokazałem ci tę funkcję a biblioteki arduino o którą pytasz - no ale aż za bardzo nawet nie mogę sobie uzmysłowić - czego w tej funkcji nie rozumiesz ? toż to czysty już kod funkcji w C .... trzeba tylko sobie &quot;opakowanie&quot; do potrzeb swojej biblioteki w C dostosować ... Tyle że wszystkie akurat inne funkcje są wg mnie mega trudniejsze niż ta jedna - a z twojego opisu wynika choć niejasno - że ty już wszystkie przerobiłeś, a została ci tylko ta ? czy jak ?<br /><br />No to jeśli tylko ta - to oczekiwałem że pojawią się jakieś szczegółowe pytania dotyczące tej funkcji i będzie jakiś ciekawy temat ....<br /><br />tymczasem - CAŁY WĄTEK to pytanie:<br /><br /><div class="quotetitle"><b>Quote:</b></div><div class="quotecontent"><br /><em><span style="color: #FF0000">&quot;nie działa mi to, dlaczego?&quot;</span></em><br /></div><br /><br />eeeeeeeh ..... eeeeeeh ..... no tak to nie można ...<br /><br />---------------------------------------------------------------<br /><br />Podsumowując - jestem też zdziwiony no ale może jednak nie masz Bluebooka czyli mojej niebieskiej książki:<br /><br /><!-- m --><a class="postlink" href="http://atnel.pl/mikrokontrolery-avr-jezyk-c.html" >http://atnel.pl/mikrokontrolery-avr-jezyk-c.html</a><!-- m --><br /><br />a może masz? ale też przecież nie napisałeś ...... tymczasem w niej masz WSZYSTKO odnośnie komunikacji I2C wyjaśnione i to w zakresie sprzętowej komunikacji za pomocą modułu TWI jak i sofwarowy przypadek biblioteki - więc po co bujać się z przeróbkami z Arduino ? ..... No chyba że tak dla sportu - to ok - ale też warto to napisać<br /><br />ostatni raz się tak rozpisałem na TAK zadane pytanie - więcej nie zabiorę głosu przy tak zadawanych pytaniach na forum <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 1 cze 2014, o 22:13</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Micron]]></name></author>
<updated>2014-06-01T18:45:14+01:00</updated>
<published>2014-06-01T18:45:14+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=82979#p82979</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=82979#p82979"/>
<title type="html"><![CDATA[Wire.endTransmission w języku c...]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=7262&amp;p=82979#p82979"><![CDATA[
Witam. Drodzy forumowicze, jak przerobić ten zapis z Arduino na C<br />Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive<br />Z góry dziękuje za pomoc.<br /><br /><br />Może inaczej <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /> mam taki zapis: <br />[syntax=c]uint8_t I2CreadByte(uint8_t address, uint8_t subAddress) {<br />//uint8_t data; // `data` will store the register data<br />//Wire.beginTransmission(address);         // Initialize the Tx buffer<br />//Wire.write(subAddress);                 // Put slave register address in Tx buffer<br />//Wire.endTransmission(false);             // Send the Tx buffer, but send a restart to keep connection alive<br />//Wire.requestFrom(address, (uint8_t) 1);  // Read one byte from slave register address<br />//data = Wire.read();                      // Fill Rx buffer with result<br />//return data; <br />}<br /><br />i zrobiłem taki w c:<br />uint8_t I2CreadByte(uint8_t address, uint8_t subAddress) {<br />uint8_t data; <br />TWI_start();       <br />TWI_write(address);<br />TWI_write(subAddress);            <br />TWI_start();             <br />TWI_write(address);<br />data = TWI_read(0);  <br />return data;<br />}[/syntax]<br /><br /><span style="color: #FF0000">Kod umieszczamy w znacznikach syntax</span> <span style="color: #00FF00">rezasurmar</span><br />Nie działa mi to za dobrze, gdzie mogę mieć błąd?<br /><br /><br /><br />EDIT: W załączeniu biblioteka arduino wire:<br /><br />Wire.cpp:<br /><br />[syntax=c]/*<br />  TwoWire.cpp - TWI/I2C library for Wiring &amp; Arduino<br />  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.<br /><br />  This library is free software; you can redistribute it and/or<br />  modify it under the terms of the GNU Lesser General Public<br />  License as published by the Free Software Foundation; either<br />  version 2.1 of the License, or (at your option) any later version.<br /><br />  This library is distributed in the hope that it will be useful,<br />  but WITHOUT ANY WARRANTY; without even the implied warranty of<br />  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br />  Lesser General Public License for more details.<br /><br />  You should have received a copy of the GNU Lesser General Public<br />  License along with this library; if not, write to the Free Software<br />  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA<br /> <br />  Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts<br />*/<br /><br />extern &quot;C&quot; {<br />  #include &lt;stdlib.h&gt;<br />  #include &lt;string.h&gt;<br />  #include &lt;inttypes.h&gt;<br />  #include &quot;twi.h&quot;<br />}<br /><br />#include &quot;Wire.h&quot;<br /><br />// Initialize Class Variables //////////////////////////////////////////////////<br /><br />uint8_t TwoWire::rxBuffer&#91;BUFFER_LENGTH&#93;;<br />uint8_t TwoWire::rxBufferIndex = 0;<br />uint8_t TwoWire::rxBufferLength = 0;<br /><br />uint8_t TwoWire::txAddress = 0;<br />uint8_t TwoWire::txBuffer&#91;BUFFER_LENGTH&#93;;<br />uint8_t TwoWire::txBufferIndex = 0;<br />uint8_t TwoWire::txBufferLength = 0;<br /><br />uint8_t TwoWire::transmitting = 0;<br />void (*TwoWire::user_onRequest)(void);<br />void (*TwoWire::user_onReceive)(int);<br /><br />// Constructors ////////////////////////////////////////////////////////////////<br /><br />TwoWire::TwoWire()<br />{<br />}<br /><br />// Public Methods //////////////////////////////////////////////////////////////<br /><br />void TwoWire::begin(void)<br />{<br />  rxBufferIndex = 0;<br />  rxBufferLength = 0;<br /><br />  txBufferIndex = 0;<br />  txBufferLength = 0;<br /><br />  twi_init();<br />}<br /><br />void TwoWire::begin(uint8_t address)<br />{<br />  twi_setAddress(address);<br />  twi_attachSlaveTxEvent(onRequestService);<br />  twi_attachSlaveRxEvent(onReceiveService);<br />  begin();<br />}<br /><br />void TwoWire::begin(int address)<br />{<br />  begin((uint8_t)address);<br />}<br /><br />uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)<br />{<br />  // clamp to buffer length<br />  if(quantity &gt; BUFFER_LENGTH){<br />    quantity = BUFFER_LENGTH;<br />  }<br />  // perform blocking read into buffer<br />  uint8_t read = twi_readFrom(address, rxBuffer, quantity, sendStop);<br />  // set rx buffer iterator vars<br />  rxBufferIndex = 0;<br />  rxBufferLength = read;<br /><br />  return read;<br />}<br /><br />uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity)<br />{<br />  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);<br />}<br /><br />uint8_t TwoWire::requestFrom(int address, int quantity)<br />{<br />  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);<br />}<br /><br />uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop)<br />{<br />  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)sendStop);<br />}<br /><br />void TwoWire::beginTransmission(uint8_t address)<br />{<br />  // indicate that we are transmitting<br />  transmitting = 1;<br />  // set address of targeted slave<br />  txAddress = address;<br />  // reset tx buffer iterator vars<br />  txBufferIndex = 0;<br />  txBufferLength = 0;<br />}<br /><br />void TwoWire::beginTransmission(int address)<br />{<br />  beginTransmission((uint8_t)address);<br />}<br /><br />//<br />//Originally, 'endTransmission' was an f(void) function.<br />//It has been modified to take one parameter indicating<br />//whether or not a STOP should be performed on the bus.<br />//Calling endTransmission(false) allows a sketch to <br />//perform a repeated start. <br />//<br />//WARNING: Nothing in the library keeps track of whether<br />//the bus tenure has been properly ended with a STOP. It<br />//is very possible to leave the bus in a hung state if<br />//no call to endTransmission(true) is made. Some I2C<br />//devices will behave oddly if they do not see a STOP.<br />//<br />uint8_t TwoWire::endTransmission(uint8_t sendStop)<br />{<br />  // transmit buffer (blocking)<br />  int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1, sendStop);<br />  // reset tx buffer iterator vars<br />  txBufferIndex = 0;<br />  txBufferLength = 0;<br />  // indicate that we are done transmitting<br />  transmitting = 0;<br />  return ret;<br />}<br /><br />//This provides backwards compatibility with the original<br />//definition, and expected behaviour, of endTransmission<br />//<br />uint8_t TwoWire::endTransmission(void)<br />{<br />  return endTransmission(true);<br />}<br /><br />// must be called in:<br />// slave tx event callback<br />// or after beginTransmission(address)<br />size_t TwoWire::write(uint8_t data)<br />{<br />  if(transmitting){<br />  // in master transmitter mode<br />    // don't bother if buffer is full<br />    if(txBufferLength &gt;= BUFFER_LENGTH){<br />      setWriteError();<br />      return 0;<br />    }<br />    // put byte in tx buffer<br />    txBuffer&#91;txBufferIndex&#93; = data;<br />    ++txBufferIndex;<br />    // update amount in buffer   <br />    txBufferLength = txBufferIndex;<br />  }else{<br />  // in slave send mode<br />    // reply to master<br />    twi_transmit(&amp;data, 1);<br />  }<br />  return 1;<br />}<br /><br />// must be called in:<br />// slave tx event callback<br />// or after beginTransmission(address)<br />size_t TwoWire::write(const uint8_t *data, size_t quantity)<br />{<br />  if(transmitting){<br />  // in master transmitter mode<br />    for(size_t i = 0; i &lt; quantity; ++i){<br />      write(data&#91;i&#93;);<br />    }<br />  }else{<br />  // in slave send mode<br />    // reply to master<br />    twi_transmit(data, quantity);<br />  }<br />  return quantity;<br />}<br /><br />// must be called in:<br />// slave rx event callback<br />// or after requestFrom(address, numBytes)<br />int TwoWire::available(void)<br />{<br />  return rxBufferLength - rxBufferIndex;<br />}<br /><br />// must be called in:<br />// slave rx event callback<br />// or after requestFrom(address, numBytes)<br />int TwoWire::read(void)<br />{<br />  int value = -1;<br />  <br />  // get each successive byte on each call<br />  if(rxBufferIndex &lt; rxBufferLength){<br />    value = rxBuffer&#91;rxBufferIndex&#93;;<br />    ++rxBufferIndex;<br />  }<br /><br />  return value;<br />}<br /><br />// must be called in:<br />// slave rx event callback<br />// or after requestFrom(address, numBytes)<br />int TwoWire::peek(void)<br />{<br />  int value = -1;<br />  <br />  if(rxBufferIndex &lt; rxBufferLength){<br />    value = rxBuffer&#91;rxBufferIndex&#93;;<br />  }<br /><br />  return value;<br />}<br /><br />void TwoWire::flush(void)<br />{<br />  // XXX: to be implemented.<br />}<br /><br />// behind the scenes function that is called when data is received<br />void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)<br />{<br />  // don't bother if user hasn't registered a callback<br />  if(!user_onReceive){<br />    return;<br />  }<br />  // don't bother if rx buffer is in use by a master requestFrom() op<br />  // i know this drops data, but it allows for slight stupidity<br />  // meaning, they may not have read all the master requestFrom() data yet<br />  if(rxBufferIndex &lt; rxBufferLength){<br />    return;<br />  }<br />  // copy twi rx buffer into local read buffer<br />  // this enables new reads to happen in parallel<br />  for(uint8_t i = 0; i &lt; numBytes; ++i){<br />    rxBuffer&#91;i&#93; = inBytes&#91;i&#93;;    <br />  }<br />  // set rx iterator vars<br />  rxBufferIndex = 0;<br />  rxBufferLength = numBytes;<br />  // alert user program<br />  user_onReceive(numBytes);<br />}<br /><br />// behind the scenes function that is called when data is requested<br />void TwoWire::onRequestService(void)<br />{<br />  // don't bother if user hasn't registered a callback<br />  if(!user_onRequest){<br />    return;<br />  }<br />  // reset tx buffer iterator vars<br />  // !!! this will kill any pending pre-master sendTo() activity<br />  txBufferIndex = 0;<br />  txBufferLength = 0;<br />  // alert user program<br />  user_onRequest();<br />}<br /><br />// sets function called on slave write<br />void TwoWire::onReceive( void (*function)(int) )<br />{<br />  user_onReceive = function;<br />}<br /><br />// sets function called on slave read<br />void TwoWire::onRequest( void (*function)(void) )<br />{<br />  user_onRequest = function;<br />}<br /><br />// Preinstantiate Objects //////////////////////////////////////////////////////<br /><br />TwoWire Wire = TwoWire();[/syntax]<br /><br />Wire.h:<br /><br />[syntax=c]/*<br />  TwoWire.h - TWI/I2C library for Arduino &amp; Wiring<br />  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.<br /><br />  This library is free software; you can redistribute it and/or<br />  modify it under the terms of the GNU Lesser General Public<br />  License as published by the Free Software Foundation; either<br />  version 2.1 of the License, or (at your option) any later version.<br /><br />  This library is distributed in the hope that it will be useful,<br />  but WITHOUT ANY WARRANTY; without even the implied warranty of<br />  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br />  Lesser General Public License for more details.<br /><br />  You should have received a copy of the GNU Lesser General Public<br />  License along with this library; if not, write to the Free Software<br />  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA<br /><br />  Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts<br />*/<br /><br />#ifndef TwoWire_h<br />#define TwoWire_h<br /><br />#include &lt;inttypes.h&gt;<br />#include &quot;Stream.h&quot;<br /><br />#define BUFFER_LENGTH 32<br /><br />class TwoWire : public Stream<br />{<br />  private:<br />    static uint8_t rxBuffer&#91;&#93;;<br />    static uint8_t rxBufferIndex;<br />    static uint8_t rxBufferLength;<br /><br />    static uint8_t txAddress;<br />    static uint8_t txBuffer&#91;&#93;;<br />    static uint8_t txBufferIndex;<br />    static uint8_t txBufferLength;<br /><br />    static uint8_t transmitting;<br />    static void (*user_onRequest)(void);<br />    static void (*user_onReceive)(int);<br />    static void onRequestService(void);<br />    static void onReceiveService(uint8_t*, int);<br />  public:<br />    TwoWire();<br />    void begin();<br />    void begin(uint8_t);<br />    void begin(int);<br />    void beginTransmission(uint8_t);<br />    void beginTransmission(int);<br />    uint8_t endTransmission(void);<br />    uint8_t endTransmission(uint8_t);<br />    uint8_t requestFrom(uint8_t, uint8_t);<br />    uint8_t requestFrom(uint8_t, uint8_t, uint8_t);<br />    uint8_t requestFrom(int, int);<br />    uint8_t requestFrom(int, int, int);<br />    virtual size_t write(uint8_t);<br />    virtual size_t write(const uint8_t *, size_t);<br />    virtual int available(void);<br />    virtual int read(void);<br />    virtual int peek(void);<br />virtual void flush(void);<br />    void onReceive( void (*)(int) );<br />    void onRequest( void (*)(void) );<br />  <br />    inline size_t write(unsigned long n) { return write((uint8_t)n); }<br />    inline size_t write(long n) { return write((uint8_t)n); }<br />    inline size_t write(unsigned int n) { return write((uint8_t)n); }<br />    inline size_t write(int n) { return write((uint8_t)n); }<br />    using Print::write;<br />};<br /><br />extern TwoWire Wire;<br /><br />#endif[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1189">Micron</a> — 1 cze 2014, o 18:45</p><hr />
]]></content>
</entry>
</feed>