Difference between revisions of "I2C"
| 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(); | ||
| + | |} | ||
| Line 9: | Line 25: | ||
{{#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 || | + | | Usage || I2C_Start(); |
|} | |} | ||
| Line 27: | Line 43: | ||
{{#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 || | + | | Usage || I2C_Stop(); |
|} | |} | ||
| Line 45: | Line 61: | ||
{{#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 || | + | | Usage || I2C_Write(0x05); //transmits 0x05 on I2C lines<br />I2C_Write(var_i2cData_u8); //Transmits 8bit data stored in var_i2cData_u8 |
|} | |} | ||
| Line 63: | Line 79: | ||
{{#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 || | + | | Usage || <syntaxhightlight> |
| + | 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 | ||
| + | } | ||
| + | <syntaxhightlight/> | ||
|} | |} | ||
Revision as of 10:19, 10 January 2015
I2C
I2C_Init
| 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
| 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
| 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
| 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
| Defination | uint8_t I2C_Read(uint8_t var_ackOption_u8) |
| Input Arguments | uint8_t: Acknowledgement to be sent after data reception.
|
| 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 | <syntaxhightlight>
void mian() {
} <syntaxhightlight/> |
