Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_serI2C.h File Reference

I2C Port 1 functions. More...

Go to the source code of this file.

Detailed Description

I2C Port 1 functions.

Author
Modtronix Engineering
Compiler:
MPLAB XC16

Description

Functions for communicating with I2C Ports. It is interrupt based, and all processing is handled in the background by interrupt service routines. Internally Circular Buffers are used, allowing multiple messages to be written to the queue.

Configuration

The following defines are used to configure this module, and should be placed in projdefs.h. Note that all items marked [-DEFAULT-] are defaults, and do not have to be placed in projdefs.h if they contain desired configuration! For details, see Project Configuration.

// *********************************************************************
// --------------- I2C Configuration (from nz_serI2C.h) ----------------
// *********************************************************************
//To save space, this will remove all code to do with Listeners
//#define I2C_DONT_SUPPORT_LISTENERS
//Number of listeners that can be registered for all I2C ports, a value from 1 to 7.
#define I2C_LISTENERS 4 //[-DEFAULT-]
//---- Enable I2C1 as a "Serial Data Port" ----
#define NZ_I2C1_ENABLE
//I2C1 Interrupt priority, a value from 0 to 7. 0 will disable interrupt, 7 is highest priority.
#define nzINT_PRIORITY_I2C1 3 //[-DEFAULT-]
//Transmit and Receive buffer sizes, for compatibility, ensure it is a power of 2 value! This can be bypassed
//by using a "non power of 2" CircularBuffer implementation for this project. See nz_CircularBuffer.h for details.
#define I2C1_RXBUF_SIZE 64 //[-DEFAULT-]
#define I2C1_TXBUF_SIZE 256 //[-DEFAULT-]
//I2C1 speed, can be 10K, 20K, 50K, 100K, 400K or 1M. Can also use value, for example 78 will give 200kHz.
//IMPORTANT to limit it to speed of lowest device on bus! For example, is 400kHz for RTC on SBC66EC!
#define I2C1_BAUD I2C_BAUD_100K //[-DEFAULT-]
//Uncomment this to define your own I2C 1 TX and RX "Circular Buffers"
//#define I2C1_DONT_CREATE_CIRBUF
//I2C1 ISR timeout, default is 200ms. This is maximum time allowed from START till STOP
#define I2C1_TIMEOUT 200 //[-DEFAULT-]
//---- Enable I2C2 as a "Serial Data Port" ----
//#define NZ_I2C2_ENABLE
//I2C2 Interrupt priority, a value from 0 to 7. 0 will disable interrupt, 7 is highest priority.
#define nzINT_PRIORITY_I2C2 4 //[-DEFAULT-]
//Transmit and Receive buffer sizes, for compatibility, ensure it is a power of 2 value! This can be bypassed
//by using a "non power of 2" CircularBuffer implementation for this project. See nz_CircularBuffer.h for details.
#define I2C2_RXBUF_SIZE 32 //[-DEFAULT-]
#define I2C2_TXBUF_SIZE 32 //[-DEFAULT-]

Usage

To use this module, the following must be done:

  • Ensure a "Circular Buffer" has been added to the project, for details see Circular Buffer Usage.
  • Copy the Configuration section above (from nz_serI2C.h) to the projdefs.h file.
  • In this "Configuration" section, enable required I2C ports. For example to enable I2C 1, ensure following is uncommented:
    #define NZ_I2C1_ENABLE
  • In this "Configuration" section, change any default values if required (if default values should be used, define is not required in projdefs.h).
  • Add nz_serI2C.c and nz_serDataPorts.c to the MPLAB project.
  • Include nz_serI2C.h in the c file it is used in.
  • All DONE! The functions defined in this file can now be used in the project.

Software License Agreement

The software supplied herewith is owned by Modtronix Engineering, and is protected under applicable copyright laws. The software supplied herewith is intended and supplied to you, the Company customer, for use solely and exclusively on products manufactured by Modtronix Engineering. The code may be modified and can be used free of charge for commercial and non commercial applications. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws, as well as to civil liability for the breach of the terms and conditions of this license.

THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.

File History

2011-06-03, David H. (DH):

  • Initial version