SPI or I2C to UART Bridge
Dependents: SC16IS750_Test mbed_SC16IS750 Xadow_SC16IS750_Test Xadow_MPU9150AHRS
Revision 5:ff3e57bebb6a, committed 2014-12-24
- Comitter:
- wim
- Date:
- Wed Dec 24 01:05:49 2014 +0000
- Parent:
- 4:12446ee9f9c8
- Commit message:
- Added Repeated Start for I2C readRegister(). Set I2C clock at 100kb/s. Fixed and added some comments.
Changed in this revision
SC16IS750.cpp | Show annotated file Show diff for this revision Revisions of this file |
SC16IS750.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 12446ee9f9c8 -r ff3e57bebb6a SC16IS750.cpp --- 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] ); }
diff -r 12446ee9f9c8 -r ff3e57bebb6a SC16IS750.h --- a/SC16IS750.h Mon Dec 22 19:04:38 2014 +0000 +++ b/SC16IS750.h 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, @@ -349,7 +350,7 @@ TXLVL = 0x08 << 3, /* TX FIFO Level register - Read only */ RXLVL = 0x09 << 3, /* RX FIFO Level register - Read only */ IODIR = 0x0A << 3, /* IO Pin Direction reg - RD/WR access */ - IOSTATE = 0x0B << 3, /* IO Pin State reg - Read only */ + IOSTATE = 0x0B << 3, /* IO Pin State reg - RD/WR access */ IOINTENA = 0x0C << 3, /* IO Interrupt Enable - RD/WR access */ // reserved = 0x0D << 3, IOCTRL = 0x0E << 3, /* IO Control register - RD/WR access */ @@ -568,6 +569,7 @@ /** 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 */ @@ -575,6 +577,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 */ @@ -582,6 +585,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) */ @@ -590,6 +594,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 */ @@ -784,7 +789,7 @@ * #include "SC16IS750.h" * * I2C i2c(PTE0, PTE1); //SDA, SCL - * SC16IS750_I2C serial_i2c(&i2c, DEFAULT_SC16IS750_ADDR); + * SC16IS750_I2C serial_i2c(&i2c, SC16IS750_DEFAULT_ADDR); * * Serial pc(USBTX,USBRX); * @@ -903,6 +908,8 @@ public: /** 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) @@ -965,7 +972,6 @@ // Save Channel setting ChannelName _channel; - }; @@ -977,7 +983,7 @@ * #include "SC16IS750.h" * * I2C i2c(PTE0, PTE1); //SDA, SCL - * SC16IS752_I2C serial_i2c(&i2c, DEFAULT_SC16IS750_ADDR, NC, SC16IS750::Channel_A); + * SC16IS752_I2C serial_i2c(&i2c, SC16IS750_DEFAULT_ADDR, NC, SC16IS750::Channel_A); * * Serial pc(USBTX,USBRX); * @@ -1000,6 +1006,8 @@ public: /** Create an SC16IS752_I2C object using a specified I2C bus, slaveaddress and Channel + * 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 address of the SC16IS750