TOP Contributors

  1. MIKROE (2650 codes)
  2. Alcides Ramos (350 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (112 codes)
  5. Chisanga Mumba (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (136558 times)
  2. FAT32 Library (69785 times)
  3. Network Ethernet Library (55857 times)
  4. USB Device Library (46199 times)
  5. Network WiFi Library (41818 times)
  6. FT800 Library (41023 times)
  7. GSM click (28934 times)
  8. PID Library (26386 times)
  9. mikroSDK (26297 times)
  10. microSD click (25307 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
Library

I2c non blocking

Rating:

10

Author: dany

Last Updated: 2020-08-15

Package Version: 2.0.0.0

Category: Internal MCU modules

Downloaded: 3201 times

Followed by: 6 users

License: MIT license  

Replacement routines for I2c1_Rd and I2c1_Wr but here with timeout, so no blocking any more when a device one tries to access is not present.
The mE I2c library is still needed for the remaining I2c routines.
Implemented also the code for controllers with 2 I2c's (e.g. P18F27K40).

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "I2c non blocking" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "I2c non blocking" changes.

Do you want to report abuse regarding "I2c non blocking".

  • Information
  • Comments (1)

Library Blog

Library I2c_TimeOut

This library contains replacements for I2c1_Rd and I2c1_Wr with timeout functionality (so non blocking).
For the moment only available for P16 and P18 PIC's with only one HW I2c module.

All other routines of mE's I2c library are not replaced, and have to be used as before.


The interface of the non blocking (with TimeOut) I2c routines library is:

For controllers with 2 I2c's (e.g. P18F27K40).
              To use that possibility:
                * add {$DEFINE MULTIPLE_I2C} to a .pld file in your project
                * add {$DEFINE USE_I2C1} or {$DEFINE USE_I2C2} to a .pld file in your project.
              For Pic's with only 1 I2c bus MULTIPLE_I2C should be undefined.
 
// interface

function I2C1_Rd_TimeOut(Ack: byte; TimeOut: word): byte;
// TimeOut should be >0 !  Its value is in units of 10us, so '50' means a timeout of '500 us'
// A timeout less than 100us (value of TimeOut = 10) is useless with 100 Khz clock speed.
// This function returns the I2c value read (except when I2c timeout, see below).
// See also the variables "I2c_TimeOut" and "I2C_LastError" below.

procedure I2C1_Wr_TimeOut(data_: byte; TimeOut: word);
// TimeOut should be >0 !  Its value is in units of 10us, so '50' means a timeout of '500 us'
// A timeout less than 100us (value of TimeOut = 10) is useless with 100 Khz clock speed.
// See also the variables "I2c_TimeOut" and "I2C_LastError" below.

var I2c_TimeOut: word; // After using one of the above routines the remaining timeout can be found in this variable.
                       // Check this value for an indication how close an I2C device comes to a timeout state.
    
    I2C_LastError: byte; // Gives the success or failiure state after using one of the above routines:
    // The following values can occur:
    //   _I2C_OK: NO error, all OK
    //   _I2C_TIMEOUT: TimeOut error
    //   _I2C_NO_ACK: No acknowledge from slave (writing only)
    
const // values for I2C_LastError
   _I2C_OK      = 0;
   _I2C_TIMEOUT = 1;
   _I2C_NO_ACK  = 2;


implementation

----------------------------------------------------------------------------------------------------------
The outcome (success or some failiure) can be found in variable "I2C_LastError", see above for the possible values.
 
The routine usage is e.g.:
  ...
  I2c1_Wr_TimeOut(Data_, 250); // Write “Data_” with a timeout of 2500 microseconds (2.5 millisecs)
 
  // Check if there was a problem during above I2c write try:
 
  If (I2C_LastError = _I2C_OK)
  then ...                    // all OK
  else If (I2C_LastError = _I2C_TIMEOUT)                       
  then ...                    // timeout error, no response in time from the I2c device
  else If (I2C_LastError = _I2C_NO_ACK)
  then ...                    // no ack from the I2c device

 
If no errors occured then the time left over from the total timeOut value (in above example the "250") can be found in variable "I2c_TimeOut"

Normally an I2c transmission takes at least 90 microseconds at 100Khz, so a timeout value of less than 10 is useless.

Have fun!

 


2015-01-26: Replaced the mB files: all mB files are compilable now (which e.g. means that all "with" statements are dealt with). I could however not link and test the libraries (no mB licence).


Version 2.0, dd 2015-07-08: changed the interface of the library. Thanks Rainer Hantsch for the testing and  valuble suggestions!

Version 09-08-2020: Implemented the code for controllers with 2 I2c's (e.g. P18F27K40).
  To use that possibility:
     * add {$DEFINE MULTIPLE_I2C} to a .pld file in your project
     * add {$DEFINE USE_I2C1} or {$DEFINE USE_I2C2} to a .pld file in your project.
  For Pic's with only 1 I2c bus MULTIPLE_I2C should be undefined.

ALSO FROM THIS AUTHOR

RC5_RC6_decoders

11

RC6 and RC6 (Philips IR remote control system) decoders, decodes the Rc5/6 toggle, Rc5/6 System and Rc5/6 command. For the moment only RC6 "mode 0" (most used) can be decoded. Made for 36 Khz IR receivers with inverse output (= output active low), like the TSOP1736. -- for P16F627A, 628A, 648A --

[Learn More]

Tool: Function Calls Display

10

Shows the function calls of the project in a number of views (a.o. graphical tree).
For mP, mC and mB for PIC and dsPIC.

[Learn More]

DS1820 Examples

0

4 examples of driving the DS1820, DS18S20 and DS18B20 digital temperature sensors, using the TempSensors and the OW_Utilities libraries. The examples can also be used with PIC24 (small changes in processor initialisation needed).

[Learn More]