SPI or I2C to UART Bridge

Dependents:   SC16IS750_Test mbed_SC16IS750 Xadow_SC16IS750_Test Xadow_MPU9150AHRS

Revision:
5:ff3e57bebb6a
Parent:
4:12446ee9f9c8
--- a/SC16IS750.cpp	Mon Dec 22 19:04:38 2014 +0000
+++ b/SC16IS750.cpp	Wed Dec 24 01:05:49 2014 +0000
@@ -3,6 +3,7 @@
  *                      https://forum.sparkfun.com/viewtopic.php?f=13&t=21846
  *   v0.2 WH, Feb 2014, Added Doxygen Documentation, Added Hardware Reset pin methods. 
  *   v0.3 WH, Dec 2014, Added support for SC16IS752 dual UART.  
+ *   v0.4 WH, Dec 2014, Added Repeated Start for I2C readRegister(). Set I2C clock at 100kb/s. Fixed and added some comments.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  * and associated documentation files (the "Software"), to deal in the Software without restriction,
@@ -360,7 +361,6 @@
 }
 
 
-
 /**
   * Check that UART is connected and operational.
   *  @param  none
@@ -376,7 +376,6 @@
 }
 
 
-
 /** Determine if there is a character available to read.
   * This is data that's already arrived and stored in the receive
   * buffer (which holds 64 chars).
@@ -392,7 +391,6 @@
   else {
     return 0; 
   }
-
 }
 
 /** Determine how many characters are available to read.
@@ -585,10 +583,9 @@
 }
 
 
-
-
 /** Set direction of I/O port pins.
   * This method is specific to the SPI-I2C UART and not found on the 16750
+  * Note: The SC16IS752 does not have separate GPIOs for Channel_A and Channel_B.
   *   @param  bits Bitpattern for I/O (1=output, 0=input)
   *   @return none
   */
@@ -598,6 +595,7 @@
 
 /** Set bits of I/O port pins.
   * This method is specific to the SPI-I2C UART and not found on the 16750
+  * Note: The SC16IS752 does not have separate GPIOs for Channel_A and Channel_B.  
   *   @param  bits Bitpattern for I/O (1= set output bit, 0 = clear output bit)
   *   @return none
   */
@@ -607,6 +605,7 @@
 
 /** Get bits of I/O port pins.
   * This method is specific to the SPI-I2C UART and not found on the 16750
+  * Note: The SC16IS752 does not have separate GPIOs for Channel_A and Channel_B.  
   *   @param  none
   *   @return bits Bitpattern for I/O (1= bit set, 0 = bit cleared)
   */
@@ -617,6 +616,7 @@
 
 /** Software Reset SC16IS750 device.
   * This method is specific to the SPI-I2C UART and not found on the 16750
+  * Note: The SC16IS752 does not have separate Reset for Channel_A and Channel_B.  
   *   @param  none
   *   @return none
   */
@@ -675,9 +675,6 @@
    if (_reset != NULL) {delete _reset;}  // Reset pin
 }
 
-
-
-
 /** Write value to internal register.
   * Pure virtual, must be declared in derived class.   
   *   @param registerAddress   The address of the Register (enum RegisterName)
@@ -776,7 +773,8 @@
   */  
 SC16IS750_I2C::SC16IS750_I2C(I2C *i2c, uint8_t deviceAddress, PinName rst) : _i2c(i2c), _slaveAddress(deviceAddress & 0xFE) {
 
-  _i2c->frequency(400000);
+//  _i2c->frequency(400000);
+  _i2c->frequency(100000);  
  
   // The hardware Reset pin is optional. Test and make sure whether it exists or not to prevent illegal access.
   if (rst != NC) {
@@ -832,7 +830,8 @@
     
    w[0] = registerAddress;
     
-   _i2c->write( _slaveAddress, w, 1 );
+//   _i2c->write( _slaveAddress, w, 1 );
+   _i2c->write(_slaveAddress, w, 1, true);   //Repeated Start   
    _i2c->read( _slaveAddress, r, 1 );
 
    return ( r[0] );
@@ -912,6 +911,8 @@
 
 
 /** Create an SC16IS752_SPI object using a specified SPI bus and CS
+  * Note: The SC16IS752 does not have separate GPIOs for Channel_A and Channel_B. 
+  * Note: The SC16IS752 does not have separate Reset for Channel_A and Channel_B.     
   *
   * @param SPI &spi the SPI port to connect to 
   * @param cs  Pinname of the CS pin (active low)
@@ -952,8 +953,6 @@
 }
 
 
-
-
 /** Write value to internal register.
   * Pure virtual, must be declared in derived class.   
   *   @param registerAddress   The address of the Register (enum RegisterName)
@@ -1044,6 +1043,8 @@
 //
 
 /** Create a SC16IS752_I2C object for a bridge between I2C and a Serial port
+  * Note: The SC16IS752 does not have separate GPIOs for Channel_A and Channel_B. 
+  * Note: The SC16IS752 does not have separate Reset for Channel_A and Channel_B.     
   *
   * @param I2C &i2c the I2C port to connect to 
   * @param char deviceAddress the I2C slave address of the SC16IS750
@@ -1052,8 +1053,9 @@
   */  
 SC16IS752_I2C::SC16IS752_I2C(I2C *i2c, uint8_t deviceAddress, PinName rst, ChannelName channel) : _i2c(i2c), _slaveAddress(deviceAddress & 0xFE), _channel(channel) {
 
-  _i2c->frequency(400000);
- 
+//  _i2c->frequency(400000);
+  _i2c->frequency(100000);
+   
   // The hardware Reset pin is optional. Test and make sure whether it exists or not to prevent illegal access.
   if (rst != NC) {
     _reset = new DigitalOut(rst);   //Construct new pin 
@@ -1108,8 +1110,9 @@
     
    w[0] = registerAddress | _channel;
     
-   _i2c->write( _slaveAddress, w, 1 );
-   _i2c->read( _slaveAddress, r, 1 );
+//   _i2c->write( _slaveAddress, w, 1 );
+   _i2c->write(_slaveAddress, w, 1, true);   //Repeated Start
+   _i2c->read(_slaveAddress, r, 1 );
 
    return ( r[0] );
 }