I2C fast mode plus support library. This library works on mbed-11U24's p28&p27 only.

Dependents:   I2C_FmPlus_Hello

A sample code for I2C Fast mode plus operation.

Warning!

This code works on mbed-LPC11U24 only.

Import programI2C_FmPlus_Hello

Sample code for "I2C_FmPlus" library. I2C fast mode plus support library. This library works on mbed-11U24's p28&p27 only.

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Tue Dec 02 03:57:29 2014 +0000
Parent:
0:213903402306
Child:
2:16a05acd675b
Commit message:
1st publishing version

Changed in this revision

I2C_FmPlus.cpp Show annotated file Show diff for this revision Revisions of this file
I2C_FmPlus.h Show annotated file Show diff for this revision Revisions of this file
--- a/I2C_FmPlus.cpp	Tue Dec 02 01:17:19 2014 +0000
+++ b/I2C_FmPlus.cpp	Tue Dec 02 03:57:29 2014 +0000
@@ -2,17 +2,14 @@
  *
  *  @class   I2C_FmPlus
  *  @author  tedd
- *  @version 0.9
- *  @date    13-Jul-2012
- *
- *  Released under the MIT License: http://mbed.org/license/mit
- *
+ *  @version 1.0
+ *  @date    02-Dec-2014
  */
 
 #include    "mbed.h"
 #include    "I2C_FmPlus.h"
 
-I2C_FmPlus::I2C_FmPlus( PinName sda, PinName scl, const char *name ) : I2C( sda, scl, name )
+I2C_FmPlus::I2C_FmPlus( PinName sda, PinName scl ) : I2C( sda, scl ), _frequency( 1000 * 1000 ), _ratio( 0.4 )
 {
     LPC_IOCON->PIO0_4   &= ~0x300;
     LPC_IOCON->PIO0_4   |=  0x200;
@@ -20,8 +17,27 @@
     LPC_IOCON->PIO0_5   |=  0x200;
 }
 
+void I2C_FmPlus::frequency( float hz ) {
+    _frequency  = hz;
+    uint32_t pclk = SystemCoreClock;
+    float   i2c_scl_period   = (1.0 / hz) - 100e-9; //  for SCLH offset and rise/fall time conpensation;    
+    float   scl_period_in_clock = (float)pclk * i2c_scl_period;
+    uint32_t   low_period = scl_period_in_clock * (1.0 - _ratio);
+    uint32_t   high_period = scl_period_in_clock * _ratio;
+    // I2C Rate
+    LPC_I2C->SCLL   =  low_period  < 4 ? 4 : low_period;
+    LPC_I2C->SCLH   =  high_period < 4 ? 4 : high_period;
+}
+
+void I2C_FmPlus::duty_ratio( float ratio ) {
+    _ratio  = ratio;
+    frequency( _frequency );
+}
+
+#if 0
 void I2C_FmPlus::scl_setting( char sclh, char scll )
 {
     LPC_I2C->SCLH   =  sclh;
     LPC_I2C->SCLL   =  scll;
 }
+#endif
--- a/I2C_FmPlus.h	Tue Dec 02 01:17:19 2014 +0000
+++ b/I2C_FmPlus.h	Tue Dec 02 03:57:29 2014 +0000
@@ -2,11 +2,8 @@
  *
  *  @class   I2C_FmPlus
  *  @author  tedd
- *  @version 0.9
- *  @date    13-Jul-2012
- *
- *  Released under the MIT License: http://mbed.org/license/mit
- *
+ *  @version 1.0
+ *  @date    02-Dec-2014
  */
 
 #ifndef     MBED_I2C_FMPLUS
@@ -16,10 +13,29 @@
 
 class I2C_FmPlus : public I2C {
 public:
-    I2C_FmPlus( PinName sda, PinName scl, const char *name = NULL );
-    void scl_setting( char sclh, char scll );
+    /** Create an I2C Master interface, connected to the specified pins
+     *
+     *  @param sda I2C data line pin
+     *  @param scl I2C clock line pin
+     */
+    I2C_FmPlus( PinName sda, PinName scl );
+
+    /** Set the frequency of the I2C interface
+     *
+     *  @param hz The bus frequency in hertz
+     */
+    void frequency( float hz );
+
+    /** Set the duty ratio of SCL
+     *
+     *  @param ratio Ratio of High/(High+Low) of SCL signal
+     */
+    void duty_ratio( float ratio );
+    
+//    void scl_setting( char sclh, char scll );
 private:
-    
+    float   _frequency;
+    float   _ratio;
 }
 ;