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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-04-13T16:00:27+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=6743&amp;mode</id>
<entry>
<author><name><![CDATA[rafkins22]]></name></author>
<updated>2014-04-13T16:00:27+01:00</updated>
<published>2014-04-13T16:00:27+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6743&amp;p=77869#p77869</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6743&amp;p=77869#p77869"/>
<title type="html"><![CDATA[Xmega jako Slave - TWI I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6743&amp;p=77869#p77869"><![CDATA[
Witam. Mam problem z obsłużeniem bibliotek Atmela do magistrali TWI dla mikrokontrolerów z rodziny Xmega. Próbuje odebrać dane z Mastera. Master to Atmega, która jest na pewno skonfigurowana poprawnie, gdyż dane odbierałem na innej atmedze. Problem pojawia się gdy chcę je odebrać na Xmedze, ze względu na moje początki z tym mikrokontrolerem. Może ktoś z was miał już styczność z obsugą tych bibliotek i byłby mi w stanie pomóc <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><br /><br />twi_slave_driver.c<br />[syntax=c]/* This file has been prepared for Doxygen automatic documentation generation.*/<br />/*! \file *********************************************************************<br /> *<br /> * \brief<br /> *      XMEGA TWI slave driver source file.<br /> *<br /> *      This file contains the function implementations the XMEGA TWI slave<br /> *      driver.<br /> *<br /> *      The driver is not intended for size and/or speed critical code, since<br /> *      most functions are just a few lines of code, and the function call<br /> *      overhead would decrease code performance. The driver is intended for<br /> *      rapid prototyping and documentation purposes for getting started with<br /> *      the XMEGA TWI slave module.<br /> *<br /> *      For size and/or speed critical code, it is recommended to copy the<br /> *      function contents directly into your application instead of making<br /> *      a function call.<br /> *<br /> *      Several functions use the following construct:<br /> *          &quot;some_register = ... | (some_parameter ? SOME_BIT_bm : 0) | ...&quot;<br /> *      Although the use of the ternary operator ( if ? then : else ) is<br /> *      discouraged, in some occasions the operator makes it possible to write<br /> *      pretty clean and neat code. In this driver, the construct is used to<br /> *      set or not set a configuration bit based on a boolean input parameter,<br /> *      such as the &quot;some_parameter&quot; in the example above.<br /> *<br /> * \par Application note:<br /> *      AVR1308: Using the XMEGA TWI<br /> *<br /> * \par Documentation<br /> *      For comprehensive code documentation, supported compilers, compiler<br /> *      settings and supported devices see readme.html<br /> *<br /> * \author<br /> *      Atmel Corporation: http://www.atmel.com \n<br /> *      Support email: avr@atmel.com<br /> *<br /> * $Revision: 2598 $<br /> * $Date: 2009-07-17 17:14:34 +0200 (fr, 17 jul 2009) $  \n<br /> *<br /> * Copyright (c) 2008, Atmel Corporation All rights reserved.<br /> *<br /> * Redistribution and use in source and binary forms, with or without<br /> * modification, are permitted provided that the following conditions are met:<br /> *<br /> * 1. Redistributions of source code must retain the above copyright notice,<br /> * this list of conditions and the following disclaimer.<br /> *<br /> * 2. Redistributions in binary form must reproduce the above copyright notice,<br /> * this list of conditions and the following disclaimer in the documentation<br /> * and/or other materials provided with the distribution.<br /> *<br /> * 3. The name of ATMEL may not be used to endorse or promote products derived<br /> * from this software without specific prior written permission.<br /> *<br /> * THIS SOFTWARE IS PROVIDED BY ATMEL &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED<br /> * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF<br /> * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND<br /> * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,<br /> * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES<br /> * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;<br /> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND<br /> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT<br /> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF<br /> * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br /> *****************************************************************************/<br /><br />#include &quot;twi_slave_driver.h&quot;<br /><br /><br />/*! \brief Initalizes TWI slave driver structure.<br /> *<br /> *  Initialize the instance of the TWI Slave and set the appropriate values.<br /> *<br /> *  \param twi                  The TWI_Slave_t struct instance.<br /> *  \param module               Pointer to the TWI module.<br /> *  \param processDataFunction  Pointer to the function that handles incoming data.<br /> */<br />void TWI_SlaveInitializeDriver(TWI_Slave_t *twi,<br />                               TWI_t *module,<br />                               void (*processDataFunction) (void))<br />{<br />twi-&gt;interface = module;<br />twi-&gt;Process_Data = processDataFunction;<br />twi-&gt;bytesReceived = 0;<br />twi-&gt;bytesSent = 0;<br />twi-&gt;status = TWIS_STATUS_READY;<br />twi-&gt;result = TWIS_RESULT_UNKNOWN;<br />twi-&gt;abort = false;<br />}<br /><br /><br />/*! \brief Initialize the TWI module.<br /> *<br /> *  Enables interrupts on address recognition and data available.<br /> *  Remember to enable interrupts globally from the main application.<br /> *<br /> *  \param twi        The TWI_Slave_t struct instance.<br /> *  \param address    Slave address for this module.<br /> *  \param intLevel   Interrupt level for the TWI slave interrupt handler.<br /> */<br />void TWI_SlaveInitializeModule(TWI_Slave_t *twi,<br />                               uint8_t address,<br />                               TWI_SLAVE_INTLVL_t intLevel)<br />{<br />twi-&gt;interface-&gt;SLAVE.CTRLA = intLevel |<br />                              TWI_SLAVE_DIEN_bm |<br />                              TWI_SLAVE_APIEN_bm |<br />                              TWI_SLAVE_ENABLE_bm;<br />twi-&gt;interface-&gt;SLAVE.ADDR = (address&lt;&lt;1);<br />}<br /><br /><br />/*! \brief Common TWI slave interrupt service routine.<br /> *<br /> *  Handles all TWI transactions and responses to address match, data reception,<br /> *  data transmission, bus error and data collision.<br /> *<br /> *  \param twi The TWI_Slave_t struct instance.<br /> */<br />void TWI_SlaveInterruptHandler(TWI_Slave_t *twi)<br />{<br />uint8_t currentStatus = twi-&gt;interface-&gt;SLAVE.STATUS;<br /><br />/* If bus error. */<br />if (currentStatus &amp; TWI_SLAVE_BUSERR_bm) {<br />twi-&gt;bytesReceived = 0;<br />twi-&gt;bytesSent = 0;<br />twi-&gt;result = TWIS_RESULT_BUS_ERROR;<br />twi-&gt;status = TWIS_STATUS_READY;<br />}<br /><br />/* If transmit collision. */<br />else if (currentStatus &amp; TWI_SLAVE_COLL_bm) {<br />twi-&gt;bytesReceived = 0;<br />twi-&gt;bytesSent = 0;<br />twi-&gt;result = TWIS_RESULT_TRANSMIT_COLLISION;<br />twi-&gt;status = TWIS_STATUS_READY;<br />}<br /><br />/* If address match. */<br />else if ((currentStatus &amp; TWI_SLAVE_APIF_bm) &amp;&amp;<br />        (currentStatus &amp; TWI_SLAVE_AP_bm)) {<br /><br />TWI_SlaveAddressMatchHandler(twi);<br />}<br /><br />/* If stop (only enabled through slave read transaction). */<br />else if (currentStatus &amp; TWI_SLAVE_APIF_bm) {<br />TWI_SlaveStopHandler(twi);<br />}<br /><br />/* If data interrupt. */<br />else if (currentStatus &amp; TWI_SLAVE_DIF_bm) {<br />TWI_SlaveDataHandler(twi);<br />}<br /><br />/* If unexpected state. */<br />else {<br />TWI_SlaveTransactionFinished(twi, TWIS_RESULT_FAIL);<br />}<br />}<br /><br />/*! \brief TWI address match interrupt handler.<br /> *<br /> *  Prepares TWI module for transaction when an address match occures.<br /> *<br /> *  \param twi The TWI_Slave_t struct instance.<br /> */<br />void TWI_SlaveAddressMatchHandler(TWI_Slave_t *twi)<br />{<br />/* If application signalling need to abort (error occured). */<br />if (twi-&gt;abort) {<br />twi-&gt;interface-&gt;SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;<br />TWI_SlaveTransactionFinished(twi, TWIS_RESULT_ABORTED);<br />twi-&gt;abort = false;<br />} else {<br />twi-&gt;status = TWIS_STATUS_BUSY;<br />twi-&gt;result = TWIS_RESULT_UNKNOWN;<br /><br />/* Disable stop interrupt. */<br />uint8_t currentCtrlA = twi-&gt;interface-&gt;SLAVE.CTRLA;<br />twi-&gt;interface-&gt;SLAVE.CTRLA = currentCtrlA &amp; ~TWI_SLAVE_PIEN_bm;<br /><br />twi-&gt;bytesReceived = 0;<br />twi-&gt;bytesSent = 0;<br /><br />/* Send ACK, wait for data interrupt. */<br />twi-&gt;interface-&gt;SLAVE.CTRLB = TWI_SLAVE_CMD_RESPONSE_gc;<br />}<br />}<br /><br /><br />/*! \brief TWI stop condition interrupt handler.<br /> *<br /> *  \param twi The TWI_Slave_t struct instance.<br /> */<br />void TWI_SlaveStopHandler(TWI_Slave_t *twi)<br />{<br />/* Disable stop interrupt. */<br />uint8_t currentCtrlA = twi-&gt;interface-&gt;SLAVE.CTRLA;<br />twi-&gt;interface-&gt;SLAVE.CTRLA = currentCtrlA &amp; ~TWI_SLAVE_PIEN_bm;<br /><br />/* Clear APIF, according to flowchart don't ACK or NACK */<br />uint8_t currentStatus = twi-&gt;interface-&gt;SLAVE.STATUS;<br />twi-&gt;interface-&gt;SLAVE.STATUS = currentStatus | TWI_SLAVE_APIF_bm;<br /><br />TWI_SlaveTransactionFinished(twi, TWIS_RESULT_OK);<br /><br />}<br /><br /><br />/*! \brief TWI data interrupt handler.<br /> *<br /> *  Calls the appropriate slave read or write handler.<br /> *<br /> *  \param twi The TWI_Slave_t struct instance.<br /> */<br />void TWI_SlaveDataHandler(TWI_Slave_t *twi)<br />{<br />if (twi-&gt;interface-&gt;SLAVE.STATUS &amp; TWI_SLAVE_DIR_bm) {<br />TWI_SlaveWriteHandler(twi);<br />} else {<br />TWI_SlaveReadHandler(twi);<br />}<br />}<br /><br /><br />/*! \brief TWI slave read interrupt handler.<br /> *<br /> *  Handles TWI slave read transactions and responses.<br /> *<br /> *  \param twi The TWI_Slave_t struct instance.<br /> */<br />void TWI_SlaveReadHandler(TWI_Slave_t *twi)<br />{<br />/* Enable stop interrupt. */<br />uint8_t currentCtrlA = twi-&gt;interface-&gt;SLAVE.CTRLA;<br />twi-&gt;interface-&gt;SLAVE.CTRLA = currentCtrlA | TWI_SLAVE_PIEN_bm;<br /><br />/* If free space in buffer. */<br />if (twi-&gt;bytesReceived &lt; TWIS_RECEIVE_BUFFER_SIZE) {<br />/* Fetch data */<br />uint8_t data = twi-&gt;interface-&gt;SLAVE.DATA;<br />twi-&gt;receivedData&#91;twi-&gt;bytesReceived&#93; = data;<br /><br />/* Process data. */<br />twi-&gt;Process_Data();<br /><br />twi-&gt;bytesReceived++;<br /><br />/* If application signalling need to abort (error occured),<br /> * complete transaction and wait for next START. Otherwise<br /> * send ACK and wait for data interrupt.<br /> */<br />if (twi-&gt;abort) {<br />twi-&gt;interface-&gt;SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;<br />TWI_SlaveTransactionFinished(twi, TWIS_RESULT_ABORTED);<br />twi-&gt;abort = false;<br />} else {<br />twi-&gt;interface-&gt;SLAVE.CTRLB = TWI_SLAVE_CMD_RESPONSE_gc;<br />}<br />}<br />/* If buffer overflow, send NACK and wait for next START. Set<br /> * result buffer overflow.<br /> */<br />else {<br />twi-&gt;interface-&gt;SLAVE.CTRLB = TWI_SLAVE_ACKACT_bm |<br />                              TWI_SLAVE_CMD_COMPTRANS_gc;<br />TWI_SlaveTransactionFinished(twi, TWIS_RESULT_BUFFER_OVERFLOW);<br />}<br />}<br /><br /><br />/*! \brief TWI slave write interrupt handler.<br /> *<br /> *  Handles TWI slave write transactions and responses.<br /> *<br /> *  \param twi The TWI_Slave_t struct instance.<br /> */<br />void TWI_SlaveWriteHandler(TWI_Slave_t *twi)<br />{<br />/* If NACK, slave write transaction finished. */<br />if ((twi-&gt;bytesSent &gt; 0) &amp;&amp; (twi-&gt;interface-&gt;SLAVE.STATUS &amp;<br />                             TWI_SLAVE_RXACK_bm)) {<br /><br />twi-&gt;interface-&gt;SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;<br />TWI_SlaveTransactionFinished(twi, TWIS_RESULT_OK);<br />}<br />/* If ACK, master expects more data. */<br />else {<br />if (twi-&gt;bytesSent &lt; TWIS_SEND_BUFFER_SIZE) {<br />uint8_t data = twi-&gt;sendData&#91;twi-&gt;bytesSent&#93;;<br />twi-&gt;interface-&gt;SLAVE.DATA = data;<br />twi-&gt;bytesSent++;<br /><br />/* Send data, wait for data interrupt. */<br />twi-&gt;interface-&gt;SLAVE.CTRLB = TWI_SLAVE_CMD_RESPONSE_gc;<br />}<br />/* If buffer overflow. */<br />else {<br />twi-&gt;interface-&gt;SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;<br />TWI_SlaveTransactionFinished(twi, TWIS_RESULT_BUFFER_OVERFLOW);<br />}<br />}<br />}<br /><br /><br />/*! \brief TWI transaction finished function.<br /> *<br /> *  Prepares module for new transaction.<br /> *<br /> *  \param twi    The TWI_Slave_t struct instance.<br /> *  \param result The result of the transaction.<br /> */<br />void TWI_SlaveTransactionFinished(TWI_Slave_t *twi, uint8_t result)<br />{<br />twi-&gt;result = result;<br />twi-&gt;status = TWIS_STATUS_READY;<br />}[/syntax]<br /><br />twi_slave_driver.h<br /><br />[syntax=c]/* This file has been prepared for Doxygen automatic documentation generation.*/<br />/*! \file *********************************************************************<br /> *<br /> * \brief  XMEGA TWI slave driver header file.<br /> *<br /> *      This file contains the function prototypes and enumerator definitions<br /> *      for various configuration parameters for the XMEGA TWI slave driver.<br /> *<br /> *      The driver is not intended for size and/or speed critical code, since<br /> *      most functions are just a few lines of code, and the function call<br /> *      overhead would decrease code performance. The driver is intended for<br /> *      rapid prototyping and documentation purposes for getting started with<br /> *      the XMEGA TWI slave module.<br /> *<br /> *      For size and/or speed critical code, it is recommended to copy the<br /> *      function contents directly into your application instead of making<br /> *      a function call.<br /> *<br /> * \par Application note:<br /> *      AVR1307: Using the XMEGA TWI<br /> *<br /> * \par Documentation<br /> *      For comprehensive code documentation, supported compilers, compiler<br /> *      settings and supported devices see readme.html<br /> *<br /> * \author<br /> *      Atmel Corporation: http://www.atmel.com \n<br /> *      Support email: avr@atmel.com<br /> *<br /> * $Revision: 1569 $<br /> * $Date: 2008-04-22 13:03:43 +0200 (ti, 22 apr 2008) $  \n<br /> *<br /> * Copyright (c) 2008, Atmel Corporation All rights reserved.<br /> *<br /> * Redistribution and use in source and binary forms, with or without<br /> * modification, are permitted provided that the following conditions are met:<br /> *<br /> * 1. Redistributions of source code must retain the above copyright notice,<br /> * this list of conditions and the following disclaimer.<br /> *<br /> * 2. Redistributions in binary form must reproduce the above copyright notice,<br /> * this list of conditions and the following disclaimer in the documentation<br /> * and/or other materials provided with the distribution.<br /> *<br /> * 3. The name of ATMEL may not be used to endorse or promote products derived<br /> * from this software without specific prior written permission.<br /> *<br /> * THIS SOFTWARE IS PROVIDED BY ATMEL &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED<br /> * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF<br /> * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND<br /> * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,<br /> * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES<br /> * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;<br /> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND<br /> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT<br /> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF<br /> * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br /> *****************************************************************************/<br />#ifndef TWI_DRIVER_H<br />#define TWI_DRIVER_H<br /><br />#include &quot;avr_compiler.h&quot;<br /><br /><br />/* Transaction status defines.*/<br />#define TWIS_STATUS_READY                0<br />#define TWIS_STATUS_BUSY                 1<br /><br />/* Transaction result enumeration */<br />typedef enum TWIS_RESULT_enum {<br />TWIS_RESULT_UNKNOWN            = (0x00&lt;&lt;0),<br />TWIS_RESULT_OK                 = (0x01&lt;&lt;0),<br />TWIS_RESULT_BUFFER_OVERFLOW    = (0x02&lt;&lt;0),<br />TWIS_RESULT_TRANSMIT_COLLISION = (0x03&lt;&lt;0),<br />TWIS_RESULT_BUS_ERROR          = (0x04&lt;&lt;0),<br />TWIS_RESULT_FAIL               = (0x05&lt;&lt;0),<br />TWIS_RESULT_ABORTED            = (0x06&lt;&lt;0),<br />} TWIS_RESULT_t;<br /><br />/* Buffer size defines. */<br />#define TWIS_RECEIVE_BUFFER_SIZE         8<br />#define TWIS_SEND_BUFFER_SIZE            8<br /><br /><br /><br />/*! \brief TWI slave driver struct.<br /> *<br /> *  TWI slave struct. Holds pointer to TWI module and data processing routine,<br /> *  buffers and necessary varibles.<br /> */<br />typedef struct TWI_Slave {<br />TWI_t *interface;                               /*!&lt; Pointer to what interface to use*/<br />void (*Process_Data) (void);                    /*!&lt; Pointer to process data function*/<br />register8_t receivedData&#91;TWIS_RECEIVE_BUFFER_SIZE&#93;; /*!&lt; Read data*/<br />register8_t sendData&#91;TWIS_SEND_BUFFER_SIZE&#93;;        /*!&lt; Data to write*/<br />register8_t bytesReceived;                          /*!&lt; Number of bytes received*/<br />register8_t bytesSent;                              /*!&lt; Number of bytes sent*/<br />register8_t status;                                 /*!&lt; Status of transaction*/<br />register8_t result;                                 /*!&lt; Result of transaction*/<br />bool abort;                                     /*!&lt; Strobe to abort*/<br />} TWI_Slave_t;<br /><br /><br /><br />void TWI_SlaveInitializeDriver(TWI_Slave_t *twi,<br />                               TWI_t *module,<br />                               void (*processDataFunction) (void));<br /><br />void TWI_SlaveInitializeModule(TWI_Slave_t *twi,<br />                               uint8_t address,<br />                               TWI_SLAVE_INTLVL_t intLevel);<br /><br />void TWI_SlaveInterruptHandler(TWI_Slave_t *twi);<br />void TWI_SlaveAddressMatchHandler(TWI_Slave_t *twi);<br />void TWI_SlaveStopHandler(TWI_Slave_t *twi);<br />void TWI_SlaveDataHandler(TWI_Slave_t *twi);<br />void TWI_SlaveReadHandler(TWI_Slave_t *twi);<br />void TWI_SlaveWriteHandler(TWI_Slave_t *twi);<br />void TWI_SlaveTransactionFinished(TWI_Slave_t *twi, uint8_t result);<br /><br /><br />/*! TWI slave interrupt service routine.<br /> *<br /> *  Interrupt service routine for the TWI slave. Copy the interrupt vector<br /> *  into your code if needed.<br /> *<br />     ISR(TWIC_TWIS_vect)<br />    {<br />      TWI_SlaveInterruptHandler(&amp;twiSlaveC);<br />    }<br /> *<br /> */<br /><br /><br />#endif /* TWI_DRIVER_H */[/syntax]<br /><br />No i mój kodzik na Xmegę:<br />[syntax=c]*  Author: Marta<br /> */ <br />#include &lt;stdio.h&gt;<br />#include &lt;avr\io.h&gt;<br />#include &lt;stddef.h&gt;<br />#include &lt;avr\interrupt.h&gt;<br />#include &quot;hd44780.h&quot;<br />#include &quot;twi_slave_driver/twi_slave_driver.h&quot;<br /><br />//#define F_CPU 2000000 <br /><br />/*! Defining an example slave address. */<br />#define SLAVE_ADDRESS 0x02<br /><br />/*! Defining number of bytes in buffer. */<br />#define NUM_BYTES 8<br /><br />/*! CPU speed 2MHz, BAUDRATE 100kHz and Baudrate Register Settings */<br />#define CPU_SPEED   2000000<br />#define BAUDRATE100000<br />#define TWI_BAUDSETTING TWI_BAUD(CPU_SPEED, BAUDRATE)<br /><br />uint8_t recv_data&#91;NUM_BYTES&#93; = {<br />     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00<br />};<br /><br />/* Global variables */<br />TWI_Slave_t twiSlave; /*!&lt; TWI slave module. */<br /><br />static void slave_process(void) {<br />     int i;<br />     for(i = 0; i &lt; NUM_BYTES; i++) {<br />        recv_data&#91;i&#93; = slave.receivedData&#91;i&#93;;<br />     }<br /> }<br /><br />void slave_init(void)<br />{<br />/* Initialize TWI slave. */<br />TWI_SlaveInitializeDriver(&amp;twiSlave, &amp;TWIC, *slave_process);<br />TWI_SlaveInitializeModule(&amp;twiSlave,SLAVE_ADDRESS,TWI_SLAVE_INTLVL_LO_gc);<br />/* Enable LO interrupt level. */<br />PMIC.CTRL |= PMIC_LOLVLEN_bm;<br />sei();<br />}<br /><br /><br />int main(void)<br />{<br />PORTCFG.MPCMASK = 0x03; // Configure several PINxCTRL registers at the same time<br />PORTC.PIN0CTRL = (PORTC.PIN0CTRL &amp; ~PORT_OPC_gm) | PORT_OPC_PULLUP_gc; //Enable pull-up to get a defined level on the switches<br /><br />slave_init();<br />LcdInit();<br />LcdClear();<br /><br /><br /><br />    while(1)<br />    {<br /><br /><br />LcdGoto(0,0);<br />LcdWrite(&quot;SIGMA S.A&quot;);<br />LcdGoto(0,1);<br />LcdDec(recv_data&#91;0&#93;);<br /><br /><br /><br /><br />    }<br />}<br /><br /><br />ISR(TWIC_TWIS_vect)<br />{<br />TWI_SlaveInterruptHandler(&amp;twiSlave);<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=488">rafkins22</a> — 13 kwi 2014, o 16:00</p><hr />
]]></content>
</entry>
</feed>