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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-04-23T17:37:53+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=6857&amp;mode</id>
<entry>
<author><name><![CDATA[jark]]></name></author>
<updated>2014-04-23T17:37:53+01:00</updated>
<published>2014-04-23T17:37:53+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6857&amp;p=78944#p78944</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6857&amp;p=78944#p78944"/>
<title type="html"><![CDATA[Re: Przedziwny problem z biblioteką &quot;komendy AT&quot;]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6857&amp;p=78944#p78944"><![CDATA[
Witam.<br />Generalnie przy takich objawach jak zmieniałeś w innym miejscu a błędy wywala Ci gdzie indziej to zazwyczaj oznacza, że albo gdzieś masz za dużo/ za mało o klamrę (nie domykasz funkcji itd) lub np. zgubiłeś średnik w pliku z deklaracjami funkcji. ja tylko zauważyłem, że w  pliku bmp085.h w linii 60 na końcu nie masz średnika ale być może w innych w których też coś zmieniałeś jest podobny problem.<br /><div class="quotetitle">Atlantis napisał(a):</div><div class="quotecontent"><br />int32_t bmp085GetPressure(uint32_t up);<br />    void BMP085_Calibration(int16_t BMP085_calibration_int16_t[],int16_t BMP085_calibration_uint16_t[], uint8_t* errorcode)<br />     <br />    #endif<br /><br />GeSHi<br /></div><br />Pozdrawiam<br />Jarek<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=582">jark</a> — 23 kwi 2014, o 17:37</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Atlantis]]></name></author>
<updated>2014-04-23T15:25:30+01:00</updated>
<published>2014-04-23T15:25:30+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6857&amp;p=78939#p78939</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6857&amp;p=78939#p78939"/>
<title type="html"><![CDATA[Przedziwny problem z biblioteką &quot;komendy AT&quot;]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6857&amp;p=78939#p78939"><![CDATA[
W jednym ze swoich projektów wykorzystuję bibliotekę do obsługi komend, dołączoną do zielonej książki.<br />Projekt na ukończeniu, przed chwilą wszystko działało. Wprowadzałem pewne poprawki do kodu, przy czym zdecydowana większość dotyczyła zupełnie innego pliku źródłowego. W kodzie odpowiedzialnym za obsługę komend zmieniłem zaledwie kilka linijek w pewnej procedurze.<br />Próbuję skompilować i niespodzianka... Atmel Studio sypie błędami i warningami, ale nie tam, gdzie coś zmieniałem. Czepia się fragmentu, który jeszcze chwilę temu nie sprawiał żadnych problemów problemów.<br /><br />Błędy wyglądają następująco:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">Error   1   parameter 'polecenia_at' is initialized   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   21   1   main<br />Warning   2   '__progmem__' attribute ignored &#91;-Wattributes&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   21   1   main<br />Warning   3   braces around scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   23   3   main<br />Warning   4   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   23   3   main<br />Warning   5   initialization from incompatible pointer type &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   23   3   main<br />Warning   6   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   23   3   main<br />Warning   7   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   23   3   main<br />Warning   8   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   23   3   main<br />Warning   9   braces around scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   24   3   main<br />Warning   10   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   24   3   main<br />Warning   11   initialization from incompatible pointer type &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   24   3   main<br />Warning   12   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   24   3   main<br />Warning   13   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   24   3   main<br />Warning   14   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   24   3   main<br />Warning   15   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   24   3   main<br />Warning   16   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   24   3   main<br />Warning   17   braces around scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   25   3   main<br />Warning   18   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   25   3   main<br />Warning   19   initialization from incompatible pointer type &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   25   3   main<br />Warning   20   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   25   3   main<br />Warning   21   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   25   3   main<br />Warning   22   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   25   3   main<br />Warning   23   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   25   3   main<br />Warning   24   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   25   3   main<br />Warning   25   braces around scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   26   3   main<br />Warning   26   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   26   3   main<br />Warning   27   initialization from incompatible pointer type &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   26   3   main<br />Warning   28   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   26   3   main<br />Warning   29   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   26   3   main<br />Warning   30   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   26   3   main<br />Warning   31   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   26   3   main<br />Warning   32   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   26   3   main<br />Warning   33   braces around scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   27   3   main<br />Warning   34   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   27   3   main<br />Warning   35   initialization from incompatible pointer type &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   27   3   main<br />Warning   36   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   27   3   main<br />Warning   37   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   27   3   main<br />Warning   38   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   27   3   main<br />Warning   39   excess elements in scalar initializer &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   27   3   main<br />Warning   40   (near initialization for 'polecenia_at') &#91;enabled by default&#93;   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   27   3   main<br />Error   41   expected '=', ',', ';', 'asm' or '__attribute__' before '{' token   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   34   1   main<br />Error   42   expected '=', ',', ';', 'asm' or '__attribute__' before '{' token   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   102   65   main<br />Error   43   expected '=', ',', ';', 'asm' or '__attribute__' before '{' token   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   110   66   main<br />Error   44   expected '=', ',', ';', 'asm' or '__attribute__' before '{' token   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   118   66   main<br />Error   45   expected '=', ',', ';', 'asm' or '__attribute__' before '{' token   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   136   67   main<br />Error   46   expected '=', ',', ';', 'asm' or '__attribute__' before '{' token   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   149   67   main<br />Error   47   old-style parameter declarations in prototyped function definition   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\BMP085\bmp085.h   60   6   main<br />Error   48   expected '{' at end of input   D:\Dokumenty\Atmel Studio\6.1\EtherGeiger_\main\AT\komendy_at.c   159   1   main<br /><br /></div><br /><br />plik komendy_at.h wygląda następująco:<br />[syntax=c].................[/syntax]<br /><br />Treść pliku komendy_at.c:<br />[syntax=c].................[/syntax]<br /><br /><br /><strong><span style="color: #FF0000">NIE UMIESZCZAMY NA FORUM CAŁYCH BIBLIOTEK Z KSIĄŻEK ANI ICH FRAGMENTÓW - Sonix</span></strong><br /><br />Ktoś mi powie co może być nie tak? Sytuacja mnie zaskoczyła i nie mam zielonego pojęcia co zrobić z tą sytuacją...<br />Czy coś przez przypadek zmieniłem? Jeśli tak, to co?<br />W przypływie desperacji spróbowałem nawet poprzenosić poszczególne pliki źródłowe do nowego projektu. Nie pomogło...<br /><br /><strong>UPDATE:</strong><br />Właśnie zauważyłem, że jeśli tylko umieszczę całą treść biblioteki komendy_AT w komentarzu, to taki sam zestaw błędów pojawia się w następnej bibliotece.<br />Występuje jedna prawidłowość - czepia się do zmiennych extern...<br /><br /><strong>UPDATE2:</strong><br /><br />Wychodzi jednak na to, że dodane biblioteki coś psują w kodzie. Po ich odkomentowaniu wszystko się kompiluje.<br />Poniżej treść kłopotliwych plików:<br /><br />bmp085.c<br />[syntax=c]//#################################################################################<br />//#################################################################################<br />//#################################################################################<br />/*Library to use BMP085 with ATMEL Atmega family<br /><br />Copyright (C) 2010 Stefan Sicklinger<br /><br />For support check out http://www.sicklinger.com<br />    <br />This library is free software: you can redistribute it and/or modify<br />    it under the terms of the GNU General Public License as published by<br />    the Free Software Foundation, either version 3 of the License, or<br />    (at your option) any later version.<br /><br />    This program 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<br />    GNU General Public License for more details.<br /><br />    You should have received a copy of the GNU General Public License<br />    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.*/<br /><br />/*  Tested with STK-600 Atmega32 @ 8MHz */<br /><br />/* Error codes:<br />   100 complete time out<br />   10  TWI wrong status<br />   0   no error */<br /><br />//#################################################################################<br />//#################################################################################<br />//#################################################################################<br /><br />#include &quot;bmp085.h&quot;<br />#include &quot;twi.h&quot;<br /><br /><br /> int32_t temperature = 0;<br /> int32_t pressure = 0;<br /> <br /> int16_t ac1;<br /> int16_t ac2;<br /> int16_t ac3;<br /> uint16_t ac4;<br /> uint16_t ac5;<br /> uint16_t ac6;<br /> int16_t b1;<br /> int16_t b2;<br /> int16_t mb;<br /> int16_t mc;<br /> int16_t md;<br /> <br /> // b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)<br /> // so ...Temperature(...) must be called before ...Pressure(...).<br /> int32_t b5;<br /> <br /> uint8_t error_code=0;<br /><br /><br />uint16_t bmp085ReadShort(uint8_t address, uint8_t* error_code)<br />{<br />uint16_t msb=0;<br />uint16_t lsb=0;<br />uint16_t data;<br />//Send Start Condition<br />i2cSendStart();<br />*error_code=i2cWaitForComplete();<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_START);<br />}<br /><br />//Tell Salve go in receive mode<br />if (*error_code==0){<br />i2cSendByte(BMP085_W);// write 0xEE<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MT_SLA_ACK);<br />}<br /><br />//Send read address to Salve<br />if (*error_code==0){<br />i2cSendByte(address);// write register address<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MT_DATA_ACK);<br />}<br /><br />//Send Restart to Slave<br />if (*error_code==0){<br />i2cSendStart();<br />*error_code=i2cWaitForComplete();<br />}<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_REP_START);<br />}<br /><br /><br />//Tell Salve go in send mode<br />if (*error_code==0){<br />i2cSendByte(BMP085_R);// read 0xEF<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MR_SLA_ACK);<br />}<br /><br /><br />//Get MSB from Salve<br />if (*error_code==0){<br />i2cReceiveByteACK();<br />*error_code=i2cWaitForComplete();<br />}<br /><br />if (*error_code==0){<br />msb = i2cGetReceivedByte();// Get MSB result<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKM<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MR_DATA_ACK);<br />}<br /><br /><br />//Get LSB from Slave<br />if (*error_code==0){<br />i2cReceiveByteNACK();<br />*error_code=i2cWaitForComplete();<br />}<br /><br />if (*error_code==0){<br />lsb = i2cGetReceivedByte();// Get LSB result<br />*error_code=i2cWaitForComplete();<br />}<br />//NACKM<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MR_DATA_NACK);<br />}<br /><br /><br />//Send Stop on the Bus<br />if (*error_code==0){<br />*error_code=i2cSendStop();<br />}<br /><br />data = (msb &lt;&lt; 8) + lsb;<br />return data;<br />}<br />//----------------------------------------<br />// <br />//----------------------------------------<br />int32_t bmp085ReadUT(uint8_t* error_code)<br />{<br /><br />int32_t ut = 0;<br />//Send Start Condition<br />i2cSendStart();<br />*error_code=i2cWaitForComplete();<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_START);<br />}<br /><br />//Tell Salve go in receive mode<br />if (*error_code==0){<br />i2cSendByte(BMP085_W);// write 0xEE<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MT_SLA_ACK);<br />}<br /><br />//Write control register address<br />if (*error_code==0){<br />i2cSendByte(0xF4);// write 0xF4<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MT_DATA_ACK);<br />}<br /><br />//Write control register value<br />if (*error_code==0){<br />i2cSendByte(0x2E);// write 0x2E<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MT_DATA_ACK);<br />}<br /><br /><br />//Send Stop on the Bus<br />if (*error_code==0){<br />*error_code=i2cSendStop();<br />}<br />//printf(&quot;error code: %d \n&quot;,error_code);<br /><br />_delay_ms(5);// min time is 4.5ms<br /><br />if (*error_code==0){<br />ut = bmp085ReadShort(0xF6,error_code);<br />}<br /><br />return ut;<br />}<br /><br /><br />int32_t bmp085ReadUP(uint8_t* error_code)<br />{<br />int32_t up = 0;<br />//Send Start Condition<br />i2cSendStart();<br />*error_code=i2cWaitForComplete();<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_START);<br />}<br /><br />//Tell Salve go in receive mode<br />if (*error_code==0){<br />i2cSendByte(BMP085_W);// write 0xEE<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MT_SLA_ACK);<br />}<br /><br />//Write control register address<br />if (*error_code==0){<br />i2cSendByte(0xF4);// write 0xF4<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MT_DATA_ACK);<br />}<br /><br />//Write control register value<br />if (*error_code==0){<br />i2cSendByte(0x34+(OSS&lt;&lt;6));// write 0x34+(OSS&lt;&lt;6)<br />*error_code=i2cWaitForComplete();<br />}<br />//ACKS<br />if (*error_code==0){<br />*error_code=checki2cReturnCode(TW_MT_DATA_ACK);<br />}<br /><br /><br />//Send Stop on the Bus<br />if (*error_code==0){<br />*error_code=i2cSendStop();<br />}<br /><br />_delay_ms(16);// min time is 15ms<br /><br />if (*error_code==0){<br />up = bmp085ReadShort(0xF6,error_code);<br />up = pressure &lt;&lt; 8;<br />up = pressure &gt;&gt; (8-OSS);<br />}<br /><br />return up;<br /><br />}<br /><br /><br />int16_t bmp085GetTemperature(uint16_t ut)<br />{<br />int32_t x1, x2;<br /><br />x1 = (((int32_t)ut - (int32_t)ac6)*(int32_t)ac5) &gt;&gt; 15;<br />x2 = ((int32_t)mc &lt;&lt; 11)/(x1 + md);<br />b5 = x1 + x2;<br /><br />return ((b5 + 8)&gt;&gt;4);<br />}<br /><br /><br />int32_t bmp085GetPressure(uint32_t up)<br />{<br />int32_t x1, x2, x3, b3, b6, p;<br />uint32_t b4, b7;<br /><br />b6 = b5 - 4000;<br />// Calculate B3<br />x1 = (b2 * (b6 * b6)&gt;&gt;12)&gt;&gt;11;<br />x2 = (ac2 * b6)&gt;&gt;11;<br />x3 = x1 + x2;<br />b3 = (((((int32_t)ac1)*4 + x3)&lt;&lt;OSS) + 2)&gt;&gt;2;<br /><br />// Calculate B4<br />x1 = (ac3 * b6)&gt;&gt;13;<br />x2 = (b1 * ((b6 * b6)&gt;&gt;12))&gt;&gt;16;<br />x3 = ((x1 + x2) + 2)&gt;&gt;2;<br />b4 = (ac4 * (uint32_t)(x3 + 32768))&gt;&gt;15;<br /><br />b7 = ((uint32_t)(up - b3) * (50000&gt;&gt;OSS));<br />if (b7 &lt; 0x80000000)<br />p = (b7&lt;&lt;1)/b4;<br />else<br />p = (b7/b4)&lt;&lt;1;<br /><br />x1 = (p&gt;&gt;8) * (p&gt;&gt;8);<br />x1 = (x1 * 3038)&gt;&gt;16;<br />x2 = (-7357 * p)&gt;&gt;16;<br />p += (x1 + x2 + 3791)&gt;&gt;4;<br /><br />return p;<br />}<br /><br /><br /><br />void BMP085_Calibration(int16_t BMP085_calibration_int16_t&#91;&#93;,int16_t BMP085_calibration_uint16_t&#91;&#93;, uint8_t* errorcode)<br />{<br /><br />if (*errorcode==0){<br />ac1 = bmp085ReadShort(0xAA,errorcode);//ac1<br />}<br />if (*errorcode==0){<br />ac2 = bmp085ReadShort(0xAC,errorcode);//ac2<br />}<br />if (*errorcode==0){<br />ac3 = bmp085ReadShort(0xAE,errorcode);//ac3<br />}<br />if (*errorcode==0){<br />ac4 = bmp085ReadShort(0xB0,errorcode);//ac4<br />}<br />if (*errorcode==0){<br />ac5 = bmp085ReadShort(0xB2,errorcode);//ac5<br />}<br />if (*errorcode==0){<br />a6 = bmp085ReadShort(0xB4,errorcode);//ac6<br />}<br />if (*errorcode==0){<br />b1 = bmp085ReadShort(0xB6,errorcode);//b1<br />}<br />if (*errorcode==0){<br />b2 = bmp085ReadShort(0xB8,errorcode);//b2<br />}<br />if (*errorcode==0){<br />mb = bmp085ReadShort(0xBA,errorcode);//mb<br />}<br />if (*errorcode==0){<br />mc = bmp085ReadShort(0xBC,errorcode);//mc<br />}<br />if (*errorcode==0){<br />md = bmp085ReadShort(0xBE,errorcode);//md<br />}<br /><br /><br />}[/syntax]<br /><br />bmp085.h<br />[syntax=c]//#################################################################################<br />//#################################################################################<br />//#################################################################################<br />/*Library to use BMP085 with ATMEL Atmega family<br /><br />Copyright (C) 2010 Stefan Sicklinger<br /><br />For support check out http://www.sicklinger.com<br />    <br />This library is free software: you can redistribute it and/or modify<br />    it under the terms of the GNU General Public License as published by<br />    the Free Software Foundation, either version 3 of the License, or<br />    (at your option) any later version.<br /><br />    This program 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<br />    GNU General Public License for more details.<br /><br />    You should have received a copy of the GNU General Public License<br />    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;. */<br />//#################################################################################<br />//#################################################################################<br />//#################################################################################<br /><br />#ifndef _BMP085_H_<br />#define _BMP085_H_<br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;stdint.h&gt;<br />#include &lt;util/twi.h&gt;<br />#include &lt;math.h&gt;<br /><br />//----------------------------------------<br />// Set BMP085 oversampling<br />//----------------------------------------<br />#define OSS 2// Oversampling Setting works for 0,1,2 NOT for 3 (not implemented)<br />//----------------------------------------<br />// Do NOT change<br />//----------------------------------------<br />#define BMP085_R 0xEF<br />#define BMP085_W 0xEE<br /><br />extern int32_t temperature;<br />extern int32_t pressure;;<br />extern uint8_t error_code;<br /><br /><br />//----------------------------------------<br />// Prototypes<br />//----------------------------------------<br />void input_init(void);<br />void BMP085_Calibration(int16_t BMP085_calibration_int16_t&#91;&#93;,int16_t BMP085_calibration_uint16_t&#91;&#93;, uint8_t* errorcode);<br />uint16_t bmp085ReadShort(uint8_t address, uint8_t* errorcode);<br />int32_t bmp085ReadUT(uint8_t* error_code);<br />int32_t bmp085ReadUP(uint8_t* errorcode);<br />int16_t bmp085GetTemperature(uint16_t ut);<br />int32_t bmp085GetPressure(uint32_t up);<br />void BMP085_Calibration(int16_t BMP085_calibration_int16_t&#91;&#93;,int16_t BMP085_calibration_uint16_t&#91;&#93;, uint8_t* errorcode)<br /><br />#endif[/syntax]<br /><br />twi.c<br />[syntax=c]/*<br /> * twi.c<br /> *<br /> * Created: 2014-04-21 00:48:10<br /> *  Author: Marek<br /> */ <br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &quot;twi.h&quot;<br /><br />void i2cSetBitrate(uint16_t bitratekHz)<br />{<br />uint8_t bitrate_div;<br />// set i2c bitrate<br />// Set Prescaler to one --&gt; TWPS = 1<br />TWSR =((0&lt;&lt;TWPS0)|(0&lt;&lt;TWPS1));<br />//calculate bitrate division<br />bitrate_div = (((float)F_CPU/1000.0)/(float)bitratekHz);<br />if(bitrate_div &gt;= 16){<br />bitrate_div = (float)(bitrate_div-16)/8;<br />}<br />//printf(&quot;DIV: %d \n&quot;,bitrate_div);<br />TWBR=(uint8_t)bitrate_div;<br />//TWBR=0; -&gt; max speed<br />}<br />//----------------------------------------<br />//<br />//----------------------------------------<br />void i2cSendStart(void)<br />{<br />// send start condition<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWSTA)|(1&lt;&lt;TWEN);<br />}<br />//----------------------------------------<br />//<br />//----------------------------------------<br />uint8_t i2cSendStop(void)<br />{<br /><br />uint8_t i = 0;//time out variable<br />uint8_t error_code=0;<br />// transmit stop condition<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN)|(1&lt;&lt;TWSTO);<br /><br />// wait until stop condition is executed and bus released<br />while ((TWCR &amp; (1&lt;&lt;TWSTO)) &amp;&amp; (i &lt; 90)){<br />_delay_us(1);<br />i++;<br />}<br />if (i&gt;89){<br />_delay_us(1);<br />error_code=100;<br /><br />}<br />return error_code;<br />}<br />//----------------------------------------<br />//<br />//----------------------------------------<br />void i2cSendByte(unsigned char data)<br />{<br />// save data to the TWDR<br />TWDR = data;<br />// begin send<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN);<br />}<br />//----------------------------------------<br />//<br />//----------------------------------------<br />void i2cReceiveByteACK(void)<br />{<br /><br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN)|(1&lt;&lt;TWEA);<br />}<br />//----------------------------------------<br />//<br />//----------------------------------------<br />void i2cReceiveByteNACK(void)<br />{<br /><br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN);<br />}<br />//----------------------------------------<br />//<br />//----------------------------------------<br />uint8_t i2cWaitForComplete(void)<br />{<br />uint8_t i = 0;//time out variable<br />uint8_t error_code=0;<br /><br />// wait for i2c interface to complete operation<br />while ((!(TWCR &amp; (1&lt;&lt;TWINT))) &amp;&amp; (i &lt; 90)){<br />_delay_us(1);<br />i++;<br />}<br />if (i&gt;89){<br />_delay_us(1);<br />error_code=100;<br /><br />}<br />return error_code;<br />}<br />//----------------------------------------<br />//<br />//----------------------------------------<br />uint8_t i2cGetReceivedByte(void)<br />{<br />// retieve received data byte from i2c TWDR<br />return (uint8_t)TWDR;<br />}<br />//----------------------------------------<br />//<br />//----------------------------------------<br />uint8_t checki2cReturnCode(uint8_t expected_return_code){<br />uint8_t error_code=0;<br />uint8_t i=0;<br />//while (error_code!=0 &amp;&amp; i!=0 &amp;&amp; i&lt;3){<br />if ((TWSR &amp; 0xF8) != expected_return_code){<br />error_code=10;<br />}<br />i++;<br />//}<br />return error_code;<br />}[/syntax]<br /><br />twi.h<br />[syntax=c]/*<br /> * twi.h<br /> *<br /> * Created: 2014-04-21 00:46:34<br /> *  Author: Marek<br /> */ <br /><br /><br />#ifndef TWI_H_<br />#define TWI_H_<br /><br />//----------------------------------------<br />// Prototypes<br />//----------------------------------------<br />//! Set the I2C transaction bitrate (in KHz)<br />void i2cSetBitrate(uint16_t bitratekHz);<br />//! Send an I2C start condition in Master mode or repeated start condition<br />void i2cSendStart(void);<br />//! Send an I2C stop condition in Master mode<br />uint8_t i2cSendStop(void);<br />//! Send an (address|R/W) combination or a data byte over I2C<br />void i2cSendByte(unsigned char data);<br />//! Receive a data byte over I2C<br />void i2cReceiveByteACK(void);<br />//! Receive a data byte over I2C<br />void i2cReceiveByteNACK(void);<br />// get received byte back<br />uint8_t i2cGetReceivedByte(void);<br />//! Wait for current I2C operation to complete<br />uint8_t i2cWaitForComplete(void);<br />// Check for expected error code<br />uint8_t checki2cReturnCode(uint8_t expected_return_code);<br /><br /><br /><br />#endif /* TWI_H_ */[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2174">Atlantis</a> — 23 kwi 2014, o 15:25</p><hr />
]]></content>
</entry>
</feed>