SC16IS7xxRK
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes
SC16IS7x2 Class Reference

Class for SC16IS852 amd SC16IS862 dual SPI or I2C UART. More...

#include <SC16IS7xxRK.h>

Inheritance diagram for SC16IS7x2:
SC16IS7xxInterface

Public Member Functions

 SC16IS7x2 ()
 Default constructor.
 
virtual ~SC16IS7x2 ()
 Since the object is typically a global variable, it is not intended to be deleted.
 
SC16IS7x2withI2C (TwoWire *wire, uint8_t addr=0)
 Chip is connected by I2C.
 
SC16IS7x2withSPI (SPIClass *spi, pin_t csPin, size_t speedMHz=4)
 Chip is connected by SPI.
 
SC16IS7xxPorta ()
 Gets the port object for port A. This is required to access UART features.
 
SC16IS7xxPortb ()
 Gets the port object for port B. This is required to access UART features.
 
SC16IS7xxPortoperator[] (size_t index)
 Gets the port object by index.
 
void forEachPort (std::function< void(SC16IS7xxPort *port)> callback)
 Call callback for each port.
 
- Public Member Functions inherited from SC16IS7xxInterface
SC16IS7xxInterfacewithI2C (TwoWire *wire=&Wire, uint8_t addr=0)
 Chip is connected by I2C.
 
SC16IS7xxInterfacewithSPI (SPIClass *spi, pin_t csPin, size_t speedMHz)
 Chip is connected by SPI.
 
SC16IS7xxInterfacewithOscillatorFrequency (int freqHz)
 Set the oscillator frequency for the chip.
 
SC16IS7xxInterfacewithEnableGPIO (bool enable=true)
 Enable GPIO mode on SC16IS750, SC16IS760, SC16IS752, SC16IS762.
 
SC16IS7xxInterfacewithIRQ (pin_t irqPin, PinMode mode=INPUT_PULLUP)
 Sets the pin used for IRQ (hardware interrupts). This is optional.
 
SC16IS7xxInterfacesoftwareReset ()
 Do a software reset of the device.
 
bool powerOnCheck ()
 Do a check to see if the device is set to the expected power-on values.
 
uint8_t readRegister (uint8_t channel, uint8_t reg)
 Read a register.
 
bool writeRegister (uint8_t channel, uint8_t reg, uint8_t value)
 Write a register.
 
virtual void forEachPort (std::function< void(SC16IS7xxPort *port)> callback)=0
 Calls a callback for each port on this chip.
 

Protected Member Functions

 SC16IS7x2 (const SC16IS7x2 &)=delete
 This class is not copyable.
 
SC16IS7x2operator= (const SC16IS7x2 &)=delete
 This class is not copyable.
 
- Protected Member Functions inherited from SC16IS7xxInterface
virtual ~SC16IS7xxInterface ()
 You cannot instantiate this directly.
 
 SC16IS7xxInterface (const SC16IS7xxInterface &)=delete
 You cannot delete this directly.
 
SC16IS7xxInterfaceoperator= (const SC16IS7xxInterface &)=delete
 This class is not copyable.
 
void beginTransaction ()
 Begins a SPI or I2C transaction.
 
void endTransaction ()
 Ends a SPI or I2C transaction.
 
bool readInternal (uint8_t channel, uint8_t *buffer, size_t size)
 Internal function to read data.
 
virtual bool writeInternal (uint8_t channel, const uint8_t *buffer, size_t size)
 Internal function to write data.
 
size_t readInternalMax () const
 Maximum number of bytes that can be read by readInternal.
 
size_t writeInternalMax () const
 Maximum number of bytes that can be written by writeInternal.
 
void registerThreadFunction (std::function< void()> fn)
 Adds a new function to be called from the worker thread.
 
void threadFunction ()
 Thread function called from FreeRTOS. Never returns!
 

Protected Attributes

SC16IS7xxPort ports [2]
 The port objects. The SC16IS7x2 has the port as member variables but the SC16IS7x0 derives from port since there is only one.
 
- Protected Attributes inherited from SC16IS7xxInterface
TwoWire * wire = nullptr
 When using I2C, the Wire object, typically Wire, but could be Wire1.
 
uint8_t i2cAddr = 0
 When using I2C, the I2C address of the SC16IS7xx chip.
 
SPIClass * spi = nullptr
 When using SPI, the SPI object (typically SPI or SPI1).
 
pin_t csPin = PIN_INVALID
 When using SPI, the CS pin (required for SPI)
 
pin_t irqPin = PIN_INVALID
 Hardware IRQ from SC16IS7xx, optional.
 
size_t irqFifoLevel = 30
 Number of bytes to trigger IRQ.
 
SPISettings spiSettings
 When using SPI, the SPISettings (bit rate, bit order, mode).
 
bool enableGPIO
 Enable GPIO mode.
 
int oscillatorFreqHz = 1843200
 Oscillator frequency. Default is 1.8432 MHz, can also be 3072000 (3.072 MHz).
 
Thread * workerThread = nullptr
 Worker thread, created if registerThreadFunction() is called.
 
std::vector< std::function< void()> > threadFunctions
 Functions to call from the worker thread, added using registerThreadFunction()
 

Additional Inherited Members

- Static Public Attributes inherited from SC16IS7xxInterface
static const uint8_t RHR_THR_REG = 0x00
 Receive Holding Register (RHR) and Transmit Holding Register (THR)
 
static const uint8_t IER_REG = 0x01
 Interrupt Enable Register (IER)
 
static const uint8_t FCR_IIR_REG = 0x02
 Interrupt Identification Register (IIR) and FIFO Control Register (FCR)
 
static const uint8_t LCR_REG = 0x03
 Line Control Register (LCR)
 
static const uint8_t MCR_REG = 0x04
 Modem Control Register (MCR)
 
static const uint8_t LSR_REG = 0x05
 Line Status Register (LSR)
 
static const uint8_t MSR_REG = 0x06
 Modem Status Register (MSR)
 
static const uint8_t TCR_REG = 0x06
 Transmission control register (TCR) when MCR[2] = 1 and EFR[4] = 1.
 
static const uint8_t SPR_REG = 0x07
 Scratchpad Register (SPR) - if MCR[2] = 1 and EFR[4] = 1.
 
static const uint8_t TLR_REG = 0x07
 Transmission level register (TLR) - if MCR[2] = 1 and EFR[4] = 1.
 
static const uint8_t TXLVL_REG = 0x08
 Transmit FIFO Level register.
 
static const uint8_t RXLVL_REG = 0x09
 Receive FIFO Level register.
 
static const uint8_t IODIR_REG = 0x0a
 I/O pin Direction register.
 
static const uint8_t IOSTATE_REG = 0x0b
 I/O pins State register.
 
static const uint8_t IOINTENA_REG = 0x0c
 I/O Interrupt Enable register.
 
static const uint8_t IOCONTROL_REG = 0x0e
 I/O pins Control register.
 
static const uint8_t EFCR_REG = 0x0f
 Extra Features Control Register.
 
static const uint8_t LCR_DEFAULT = 0x1D
 Power-on default value of LCR.
 
static const uint8_t LCR_SPECIAL_ENABLE_DIVISOR_LATCH = 0x80
 LCR bit to enable setting divisor.
 
static const uint8_t LCR_ENABLE_ENHANCED_FEATURE_REG = 0xbf
 LCR bit to enable enhanced features.
 
static const uint8_t DLL_REG = 0x00
 Divisor Latch LSB (DLL)
 
static const uint8_t DLH_REG = 0x01
 Divisor Latch MSB (DLH)
 
static const uint8_t EFR_REG = 0x02
 Enhanced Features Register (EFR)
 
static const uint8_t XON1_REG = 0x04
 Xon1 word.
 
static const uint8_t XON2_REG = 0x05
 Xon2 word.
 
static const uint8_t XOFF1_REG = 0x06
 Xoff1 word.
 
static const uint8_t XOFF2_REG = 0x07
 Xoff2 word.
 
- Static Protected Member Functions inherited from SC16IS7xxInterface
static void threadFunctionStatic (void *param)
 Static thread function, called from FreeRTOS.
 

Detailed Description

Class for SC16IS852 amd SC16IS862 dual SPI or I2C UART.

Constructor & Destructor Documentation

◆ SC16IS7x2()

SC16IS7x2::SC16IS7x2 ( )

Default constructor.

You typically allocate one of these per chip as global variables.

◆ ~SC16IS7x2()

virtual SC16IS7x2::~SC16IS7x2 ( )
inlinevirtual

Since the object is typically a global variable, it is not intended to be deleted.

If you delete this object and are using the worker thread, the device will probably crash since the thread won't be stopped.

Member Function Documentation

◆ a()

SC16IS7xxPort & SC16IS7x2::a ( )
inline

Gets the port object for port A. This is required to access UART features.

Returns
SC16IS7xxPort&

◆ b()

SC16IS7xxPort & SC16IS7x2::b ( )
inline

Gets the port object for port B. This is required to access UART features.

Returns
SC16IS7xxPort&

◆ forEachPort()

void SC16IS7x2::forEachPort ( std::function< void(SC16IS7xxPort *port)>  callback)
virtual

Call callback for each port.

For the SC16IS7x2 there are two ports

Implements SC16IS7xxInterface.

◆ operator[]()

SC16IS7xxPort & SC16IS7x2::operator[] ( size_t  index)
inline

Gets the port object by index.

Parameters
indexMust be 0 (port A) or 1 (port B). Other values will crash.
Returns
SC16IS7xxPort&

◆ withI2C()

SC16IS7x2 & SC16IS7x2::withI2C ( TwoWire *  wire,
uint8_t  addr = 0 
)
inline

Chip is connected by I2C.

Parameters
wireThe I2C port, typically &Wire but could be &Wire1, etc.
addrI2C address (see note below)
Returns
SC16IS7xxInterface&

A1 A0 Index I2C Address VDD VDD 0 0x48 VDD GND 1 0x49 VDD SCL 2 0x4a VDD SDA 3 0x4b GND VDD 4 0x4c GND GND 5 0x4d GND SCL 6 0x4e GND SDA 7 0x4f SCL VDD 8 0x50 SCL GND 9 0x51 SCL SCL 10 0x52 SCL SDA 11 0x53 SDA VDD 12 0x54 SDA GND 13 0x55 SDA SCL 14 0x56 SDA SDA 15 0x57

You can pass either the index (0 - 15) or the I2C address in the address field. Note that the NXP datasheet addresses must be divided by 2 because they include the R/W bit in the address, and Particle and Arduino do not. That's why the datasheet lists the starting address as 0x90 instead of 0x48.

The SC16IS752 and SC16IS762 support up to 400 Kbit/sec I2C.

◆ withSPI()

SC16IS7x2 & SC16IS7x2::withSPI ( SPIClass *  spi,
pin_t  csPin,
size_t  speedMHz = 4 
)
inline

Chip is connected by SPI.

Parameters
spiThe SPI port. Typically &SPI but could be &SPI1, etc.
csPinThe pin used for chip select. This is required.
speedMHzThe SPI bus speed in MHz. Default is 4.
Returns
SC16IS7xxInterface&

The SC16IS752 supports SPI speeds up to 4 Mbit/sec. The SC16IS762 supports SPI speeds up to 15 Mbit/sec.


The documentation for this class was generated from the following files: