<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="sk">
	<id>https://senzor.robotika.sk/sensorwiki/index.php?action=history&amp;feed=atom&amp;title=I2cmaster.h</id>
	<title>I2cmaster.h - História úprav</title>
	<link rel="self" type="application/atom+xml" href="https://senzor.robotika.sk/sensorwiki/index.php?action=history&amp;feed=atom&amp;title=I2cmaster.h"/>
	<link rel="alternate" type="text/html" href="https://senzor.robotika.sk/sensorwiki/index.php?title=I2cmaster.h&amp;action=history"/>
	<updated>2026-05-16T01:59:25Z</updated>
	<subtitle>História úprav pre túto stránku na wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://senzor.robotika.sk/sensorwiki/index.php?title=I2cmaster.h&amp;diff=3783&amp;oldid=prev</id>
		<title>StudentDVPS: Vytvorená stránka „&lt;source lang=&quot;c&quot;&gt; #ifndef _I2CMASTER_H #define _I2CMASTER_H   1 /*************************************************************************  * Title:    C include file fo...“</title>
		<link rel="alternate" type="text/html" href="https://senzor.robotika.sk/sensorwiki/index.php?title=I2cmaster.h&amp;diff=3783&amp;oldid=prev"/>
		<updated>2013-01-15T13:04:55Z</updated>

		<summary type="html">&lt;p&gt;Vytvorená stránka „&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt; #ifndef _I2CMASTER_H #define _I2CMASTER_H   1 /*************************************************************************  * Title:    C include file fo...“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nová stránka&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#ifndef _I2CMASTER_H&lt;br /&gt;
#define _I2CMASTER_H   1&lt;br /&gt;
/************************************************************************* &lt;br /&gt;
* Title:    C include file for the I2C master interface &lt;br /&gt;
*           (i2cmaster.S or twimaster.c)&lt;br /&gt;
* Author:   Peter Fleury &amp;lt;pfleury@gmx.ch&amp;gt;  http://jump.to/fleury&lt;br /&gt;
* File:     $Id: i2cmaster.h,v 1.10 2005/03/06 22:39:57 Peter Exp $&lt;br /&gt;
* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3&lt;br /&gt;
* Target:   any AVR device&lt;br /&gt;
* Usage:    see Doxygen manual&lt;br /&gt;
**************************************************************************/&lt;br /&gt;
&lt;br /&gt;
#ifdef DOXYGEN&lt;br /&gt;
/**&lt;br /&gt;
 @defgroup pfleury_ic2master I2C Master library&lt;br /&gt;
 @code #include &amp;lt;i2cmaster.h&amp;gt; @endcode&lt;br /&gt;
  &lt;br /&gt;
 @brief I2C (TWI) Master Software Library&lt;br /&gt;
&lt;br /&gt;
 Basic routines for communicating with I2C slave devices. This single master &lt;br /&gt;
 implementation is limited to one bus master on the I2C bus. &lt;br /&gt;
&lt;br /&gt;
 This I2c library is implemented as a compact assembler software implementation of the I2C protocol &lt;br /&gt;
 which runs on any AVR (i2cmaster.S) and as a TWI hardware interface for all AVR with built-in TWI hardware (twimaster.c).&lt;br /&gt;
 Since the API for these two implementations is exactly the same, an application can be linked either against the&lt;br /&gt;
 software I2C implementation or the hardware I2C implementation.&lt;br /&gt;
&lt;br /&gt;
 Use 4.7k pull-up resistor on the SDA and SCL pin.&lt;br /&gt;
 &lt;br /&gt;
 Adapt the SCL and SDA port and pin definitions and eventually the delay routine in the module &lt;br /&gt;
 i2cmaster.S to your target when using the software I2C implementation ! &lt;br /&gt;
 &lt;br /&gt;
 Adjust the  CPU clock frequence F_CPU in twimaster.c or in the Makfile when using the TWI hardware implementaion.&lt;br /&gt;
&lt;br /&gt;
 @note &lt;br /&gt;
    The module i2cmaster.S is based on the Atmel Application Note AVR300, corrected and adapted &lt;br /&gt;
    to GNU assembler and AVR-GCC C call interface.&lt;br /&gt;
    Replaced the incorrect quarter period delays found in AVR300 with &lt;br /&gt;
    half period delays. &lt;br /&gt;
    &lt;br /&gt;
 @author Peter Fleury pfleury@gmx.ch  http://jump.to/fleury&lt;br /&gt;
&lt;br /&gt;
 @par API Usage Example&lt;br /&gt;
  The following code shows typical usage of this library, see example test_i2cmaster.c&lt;br /&gt;
&lt;br /&gt;
 @code&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;i2cmaster.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 #define Dev24C02  0xA2      // device address of EEPROM 24C02, see datasheet&lt;br /&gt;
&lt;br /&gt;
 int main(void)&lt;br /&gt;
 {&lt;br /&gt;
     unsigned char ret;&lt;br /&gt;
&lt;br /&gt;
     i2c_init();                             // initialize I2C library&lt;br /&gt;
&lt;br /&gt;
     // write 0x75 to EEPROM address 5 (Byte Write) &lt;br /&gt;
     i2c_start_wait(Dev24C02+I2C_WRITE);     // set device address and write mode&lt;br /&gt;
     i2c_write(0x05);                        // write address = 5&lt;br /&gt;
     i2c_write(0x75);                        // write value 0x75 to EEPROM&lt;br /&gt;
     i2c_stop();                             // set stop conditon = release bus&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
     // read previously written value back from EEPROM address 5 &lt;br /&gt;
     i2c_start_wait(Dev24C02+I2C_WRITE);     // set device address and write mode&lt;br /&gt;
&lt;br /&gt;
     i2c_write(0x05);                        // write address = 5&lt;br /&gt;
     i2c_rep_start(Dev24C02+I2C_READ);       // set device address and read mode&lt;br /&gt;
&lt;br /&gt;
     ret = i2c_readNak();                    // read one byte from EEPROM&lt;br /&gt;
     i2c_stop();&lt;br /&gt;
&lt;br /&gt;
     for(;;);&lt;br /&gt;
 }&lt;br /&gt;
 @endcode&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
#endif /* DOXYGEN */&lt;br /&gt;
&lt;br /&gt;
/**@{*/&lt;br /&gt;
&lt;br /&gt;
#if (__GNUC__ * 100 + __GNUC_MINOR__) &amp;lt; 304&lt;br /&gt;
#error &amp;quot;This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !&amp;quot;&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;avr/io.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */&lt;br /&gt;
#define I2C_READ    1&lt;br /&gt;
&lt;br /&gt;
/** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */&lt;br /&gt;
#define I2C_WRITE   0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 @brief initialize the I2C master interace. Need to be called only once &lt;br /&gt;
 @param  void&lt;br /&gt;
 @return none&lt;br /&gt;
 */&lt;br /&gt;
extern void i2c_init(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** &lt;br /&gt;
 @brief Terminates the data transfer and releases the I2C bus &lt;br /&gt;
 @param void&lt;br /&gt;
 @return none&lt;br /&gt;
 */&lt;br /&gt;
extern void i2c_stop(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** &lt;br /&gt;
 @brief Issues a start condition and sends address and transfer direction &lt;br /&gt;
  &lt;br /&gt;
 @param    addr address and transfer direction of I2C device&lt;br /&gt;
 @retval   0   device accessible &lt;br /&gt;
 @retval   1   failed to access device &lt;br /&gt;
 */&lt;br /&gt;
extern unsigned char i2c_start(unsigned char addr);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 @brief Issues a repeated start condition and sends address and transfer direction &lt;br /&gt;
&lt;br /&gt;
 @param   addr address and transfer direction of I2C device&lt;br /&gt;
 @retval  0 device accessible&lt;br /&gt;
 @retval  1 failed to access device&lt;br /&gt;
 */&lt;br /&gt;
extern unsigned char i2c_rep_start(unsigned char addr);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 @brief Issues a start condition and sends address and transfer direction &lt;br /&gt;
   &lt;br /&gt;
 If device is busy, use ack polling to wait until device ready &lt;br /&gt;
 @param    addr address and transfer direction of I2C device&lt;br /&gt;
 @return   none&lt;br /&gt;
 */&lt;br /&gt;
extern void i2c_start_wait(unsigned char addr);&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
/**&lt;br /&gt;
 @brief Send one byte to I2C device&lt;br /&gt;
 @param    data  byte to be transfered&lt;br /&gt;
 @retval   0 write successful&lt;br /&gt;
 @retval   1 write failed&lt;br /&gt;
 */&lt;br /&gt;
extern unsigned char i2c_write(unsigned char data);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 @brief    read one byte from the I2C device, request more data from device &lt;br /&gt;
 @return   byte read from I2C device&lt;br /&gt;
 */&lt;br /&gt;
extern unsigned char i2c_readAck(void);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 @brief    read one byte from the I2C device, read is followed by a stop condition &lt;br /&gt;
 @return   byte read from I2C device&lt;br /&gt;
 */&lt;br /&gt;
extern unsigned char i2c_readNak(void);&lt;br /&gt;
&lt;br /&gt;
/** &lt;br /&gt;
 @brief    read one byte from the I2C device&lt;br /&gt;
 &lt;br /&gt;
 Implemented as a macro, which calls either i2c_readAck or i2c_readNak&lt;br /&gt;
 &lt;br /&gt;
 @param    ack 1 send ack, request more data from device&amp;lt;br&amp;gt;&lt;br /&gt;
               0 send nak, read is followed by a stop condition &lt;br /&gt;
 @return   byte read from I2C device&lt;br /&gt;
 */&lt;br /&gt;
extern unsigned char i2c_read(unsigned char ack);&lt;br /&gt;
#define i2c_read(ack)  (ack) ? i2c_readAck() : i2c_readNak(); &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**@}*/&lt;br /&gt;
#endif&lt;/div&gt;</summary>
		<author><name>StudentDVPS</name></author>
	</entry>
</feed>