(Created page with "category:Library_Reference =I2C= ==I2C_Start== {| class="wikitable" style="colspan:1; background-color:#4682B4;" {{#Widget:LibTable}} |- |Defination || |- | Input Ar...")
 
 
(23 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
=I2C=
 
=I2C=
  
 +
 +
 +
==I2C_Init==
 +
{|{{Widget:LibCol}}
 +
{{#Widget:LibTable}}
 +
|-
 +
|Defination || void I2C_Init()
 +
|-
 +
| Input Arguments || none
 +
|-
 +
| Return Value|| none
 +
|-
 +
| Description ||  This function is used to initialize the I2C module.
 +
|-
 +
| Usage || I2C_Init();
 +
|}
  
  
 
==I2C_Start==
 
==I2C_Start==
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination || void I2C_Start()
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments || none
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||   
+
| Description ||  This function is used to generate I2C Start Condition.<br />Start Condition: SDA goes low when SCL is High.
 +
|-
 +
| Usage || I2C_Start();
 
|}
 
|}
  
Line 22: Line 40:
  
 
==I2C_Stop==  
 
==I2C_Stop==  
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination || void I2C_Stop()
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments || none
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||   
+
| Description ||  This function is used to generate I2C Stop Condition.<br />Stop Condition: SDA goes High when SCL is High.
 +
|-
 +
| Usage || I2C_Stop();
 
|}
 
|}
  
Line 38: Line 58:
  
 
==I2C_Write==
 
==I2C_Write==
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination || void I2C_Write(uint8_t var_i2cData_u8)
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments || uint8_t : 8-bit data to be transmitted.
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||
+
| Description || This function is used to send a byte on SDA line using I2C protocol.<br />8bit data is sent bit-by-bit on each clock cycle.<br />MSB(bit) is sent first and LSB(bit) is sent at last.
 +
|-
 +
| Usage || I2C_Write(0x05); //transmits 0x05 on I2C lines<br />I2C_Write(var_i2cData_u8); //Transmits 8bit data stored in var_i2cData_u8
 
|}
 
|}
  
Line 54: Line 76:
  
 
==I2C_Read==
 
==I2C_Read==
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination || uint8_t I2C_Read(uint8_t var_ackOption_u8)
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments || uint8_t: Acknowledgement to be sent after data reception.<br />
 +
*1:Positive acknowledgement<br />
 +
*0:Negative acknowledgement
 
|-
 
|-
| Return Value||  
+
| Return Value|| uint8_t: Data received form I2C lines.
 
|-
 
|-
| Description ||   
+
| Description || This fun is used to receive a byte on SDA line using I2C protocol.
 +
|-
 +
| Usage || <syntaxhighlight lang = "c">
 +
void mian()
 +
{
 +
    *ptr_sec_u8 = I2C_Read(1);                // read second and return Positive ACK
 +
    *ptr_min_u8 = I2C_Read(1);             // read minute and return Positive ACK
 +
    *ptr_hour_u8 = I2C_Read(0);              // read hour and return Negative/No ACK
 +
}
 +
</syntaxhighlight>
 
|}
 
|}
  
Line 69: Line 102:
  
 
==User_Guide==
 
==User_Guide==
 +
<syntaxhighlight  lang = "c">
 +
/*Below examples demonstrate the usage of I2C library to read and write the RTC(DS1307) time. */
 +
 +
void RTC_SetTime(uint8_t var_hour_u8, uint8_t var_min_u8, uint8_t var_sec_u8)
 +
{
 +
I2C_Start();                            // Start I2C communication
 +
 +
I2C_Write(C_Ds1307WriteMode_U8);        // connect to DS1307 by sending its ID on I2c Bus
 +
I2C_Write(C_Ds1307SecondRegAddress_U8); // Select the SEC RAM address
 +
 +
I2C_Write(var_sec_u8);               // Write sec from RAM address 00H
 +
I2C_Write(var_min_u8);               // Write min from RAM address 01H
 +
I2C_Write(var_hour_u8);               // Write hour from RAM address 02H
 +
 +
I2C_Stop();                      // Stop I2C communication after Setting the Time
 +
}
 +
 +
 +
void RTC_GetTime(uint8_t *ptr_hour_u8,uint8_t *ptr_min_u8,uint8_t *ptr_sec_u8)
 +
{
 +
I2C_Start();                              // Start I2C communication
 +
 +
I2C_Write(C_Ds1307WriteMode_U8);         // connect to DS1307 by sending its ID on I2c Bus
 +
I2C_Write(C_Ds1307SecondRegAddress_U8);  // Request Sec RAM address at 00H
 +
 +
I2C_Stop();         // Stop I2C communication after selecting Sec Register
 +
 +
I2C_Start();                 // Start I2C communication
 +
I2C_Write(C_Ds1307ReadMode_U8);          // connect to DS1307(Read mode) by sending its ID
 +
 +
*ptr_sec_u8 = I2C_Read(1);              // read second and return Positive ACK
 +
*ptr_min_u8 = I2C_Read(1);         // read minute and return Positive ACK
 +
*ptr_hour_u8 = I2C_Read(0);              // read hour and return Negative/No ACK
 +
 +
I2C_Stop();                 // Stop I2C communication after reading the Time
 +
}
 +
</syntaxhighlight>

Latest revision as of 10:48, 10 January 2015


I2C

I2C_Init

{{#Widget:LibTable}}
Defination void I2C_Init()
Input Arguments none
Return Value none
Description This function is used to initialize the I2C module.
Usage I2C_Init();


I2C_Start

{{#Widget:LibTable}}
Defination void I2C_Start()
Input Arguments none
Return Value none
Description This function is used to generate I2C Start Condition.
Start Condition: SDA goes low when SCL is High.
Usage I2C_Start();



I2C_Stop

{{#Widget:LibTable}}
Defination void I2C_Stop()
Input Arguments none
Return Value none
Description This function is used to generate I2C Stop Condition.
Stop Condition: SDA goes High when SCL is High.
Usage I2C_Stop();



I2C_Write

{{#Widget:LibTable}}
Defination void I2C_Write(uint8_t var_i2cData_u8)
Input Arguments uint8_t : 8-bit data to be transmitted.
Return Value none
Description This function is used to send a byte on SDA line using I2C protocol.
8bit data is sent bit-by-bit on each clock cycle.
MSB(bit) is sent first and LSB(bit) is sent at last.
Usage I2C_Write(0x05); //transmits 0x05 on I2C lines
I2C_Write(var_i2cData_u8); //Transmits 8bit data stored in var_i2cData_u8



I2C_Read

{{#Widget:LibTable}}
Defination uint8_t I2C_Read(uint8_t var_ackOption_u8)
Input Arguments uint8_t: Acknowledgement to be sent after data reception.
  • 1:Positive acknowledgement
  • 0:Negative acknowledgement
Return Value uint8_t: Data received form I2C lines.
Description This fun is used to receive a byte on SDA line using I2C protocol.
Usage
void mian()
{
    *ptr_sec_u8 = I2C_Read(1);                // read second and return Positive ACK
    *ptr_min_u8 = I2C_Read(1); 	             // read minute and return Positive ACK
    *ptr_hour_u8 = I2C_Read(0);              // read hour and return Negative/No ACK
}


User_Guide

/*Below examples demonstrate the usage of I2C library to read and write the RTC(DS1307) time. */
 
void RTC_SetTime(uint8_t var_hour_u8, uint8_t var_min_u8, uint8_t var_sec_u8)
{
	I2C_Start();                            // Start I2C communication
 
	I2C_Write(C_Ds1307WriteMode_U8);        // connect to DS1307 by sending its ID on I2c Bus
	I2C_Write(C_Ds1307SecondRegAddress_U8); // Select the SEC RAM address
 
	I2C_Write(var_sec_u8);	               // Write sec from RAM address 00H
	I2C_Write(var_min_u8);	               // Write min from RAM address 01H
	I2C_Write(var_hour_u8);	               // Write hour from RAM address 02H
 
	I2C_Stop();                 	      // Stop I2C communication after Setting the Time
}
 
 
void RTC_GetTime(uint8_t *ptr_hour_u8,uint8_t *ptr_min_u8,uint8_t *ptr_sec_u8)
{
	I2C_Start();                              // Start I2C communication
 
	I2C_Write(C_Ds1307WriteMode_U8);	         // connect to DS1307 by sending its ID on I2c Bus
	I2C_Write(C_Ds1307SecondRegAddress_U8);   // Request Sec RAM address at 00H
 
	I2C_Stop();			        // Stop I2C communication after selecting Sec Register
 
	I2C_Start();		                // Start I2C communication
	I2C_Write(C_Ds1307ReadMode_U8);          // connect to DS1307(Read mode) by sending its ID
 
	*ptr_sec_u8 = I2C_Read(1);               // read second and return Positive ACK
	*ptr_min_u8 = I2C_Read(1); 	        // read minute and return Positive ACK
	*ptr_hour_u8 = I2C_Read(0);              // read hour and return Negative/No ACK
 
	I2C_Stop();		                // Stop I2C communication after reading the Time
}