SC16IS752 Serial Bridge Arduino Library
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
SC16IS752 Class Reference

Driver for the NXP SC16IS752 dual UART bridge over I2C or SPI. More...

#include <SC16IS752.h>

Collaboration diagram for SC16IS752:
Collaboration graph
[legend]

Classes

class  ChannelStream
 Per-channel Stream adapter for one SC16IS752 UART. More...
 

Public Types

enum  SC16IS752_Channel : uint8_t { SC16IS752_CHANNEL_A = 0x00 , SC16IS752_CHANNEL_B = 0x01 , SC16IS752_CHANNEL_BOTH = 0x00 }
 UART channel selector used by channel-specific APIs. More...
 

Public Member Functions

 SC16IS752 (TwoWire &wire, uint8_t addr=SC16IS750_I2C_ADDRESS_AD, uint32_t crystal_freq_hz=SC16IS750_CRYSTCAL_FREQ)
 Constructs an SC16IS752 instance using I2C transport.
 
 SC16IS752 (SPIClass &spi, uint8_t ss_pin, uint32_t crystal_freq_hz=SC16IS750_CRYSTCAL_FREQ)
 Constructs an SC16IS752 instance using SPI transport.
 
 SC16IS752 (const SC16IS752 &)=delete
 Prevent copying and moving of the driver instance.
 
SC16IS752operator= (const SC16IS752 &)=delete
 Prevent copying and moving of the driver instance.
 
 SC16IS752 (SC16IS752 &&)=delete
 Prevent copying and moving of the driver instance.
 
SC16IS752operator= (SC16IS752 &&)=delete
 Prevent copying and moving of the driver instance.
 
ChannelStreamchannelA ()
 Returns channel A stream adapter.
 
ChannelStreamchannelB ()
 Returns channel B stream adapter.
 
void setLogger (SC16IS752Logger *log)
 Set logger for debug output.
 
void setTimeout (uint32_t time_out)
 Sets read timeout in milliseconds.
 
void end ()
 Gracefully closes both UART channels and resets the device.
 

Protected Member Functions

void beginChannel (SC16IS752_Channel channel, uint32_t baudrate, uint32_t config=SC16IS752_DEFAULT_CONFIG)
 Initializes a specific UART channel with the given baud rate and serial configuration.
 
void endChannel (SC16IS752_Channel channel)
 Gracefully closes a specific UART channel.
 
int read (SC16IS752_Channel channel)
 Reads a byte from the specified channel.
 
size_t write (SC16IS752_Channel channel, uint8_t val)
 Writes a byte to the specified channel.
 
int available (SC16IS752_Channel channel)
 Returns number of bytes available to read from the channel.
 
uint8_t linestate (SC16IS752_Channel channel)
 Returns line status register for the channel.
 
uint8_t ping ()
 Verifies device communication (returns 1 if successful)
 
int peek (SC16IS752_Channel channel)
 Reads a byte without removing it from the buffer.
 
void flush (SC16IS752_Channel channel)
 Waits for transmission to complete on the channel.
 
uint8_t interruptPendingTest (SC16IS752_Channel channel)
 Tests if an interrupt is pending on the channel.
 
int interruptEventTest (SC16IS752_Channel channel)
 Returns the type of interrupt event for the channel.
 
void setPinInterrupt (uint8_t io_int_ena)
 Configures GPIO pin interrupt settings.
 
void enableRs485 (SC16IS752_Channel channel, bool invert_rts)
 
void enableTransmit (SC16IS752_Channel channel, uint8_t tx_enable)
 Enables or disables transmission on the specified channel.
 
void initializeDevice ()
 Initializes the SC16IS752 device state on an already configured bus.
 
uint8_t gpioGetPortState (void)
 Returns the current state of all GPIO pins as a bitmask.
 
void interruptControl (SC16IS752_Channel channel, uint8_t int_ena)
 Writes interrupt enable flags for the selected UART channel.
 
void modemPin (uint8_t gpio)
 Selects whether upper IO pins operate as modem pins or GPIO pins.
 
void gpioLatch (uint8_t latch)
 Enables or disables GPIO output latching behavior.
 
int16_t setBaudrate (SC16IS752_Channel channel, uint32_t baudrate)
 Configures baud rate divisor and returns error in parts-per-thousand.
 
uint8_t readRegister (SC16IS752_Channel channel, uint8_t reg_addr)
 Reads one register byte from the selected channel via I2C or SPI.
 
void writeRegister (SC16IS752_Channel channel, uint8_t reg_addr, uint8_t val)
 Writes one register byte to the selected channel via I2C or SPI.
 
void setLine (SC16IS752_Channel channel, uint8_t data_length, uint8_t parity_select, uint8_t stop_length)
 Configures line format by data bits, parity mode, and stop bits.
 
void setLine (SC16IS752_Channel channel, uint32_t config)
 Configures data bits, parity, and stop bits from an Arduino SERIAL_* value.
 
void pinMode (uint8_t pin, uint8_t io)
 Sets GPIO pin as input or output (OUTPUT or INPUT)
 
void digitalWrite (uint8_t pin, uint8_t value)
 Sets GPIO pin output level (HIGH or LOW)
 
uint8_t digitalRead (uint8_t pin)
 Reads GPIO pin level (returns 0 or 1)
 
void gpioSetPinMode (uint8_t pin_number, uint8_t i_o)
 Sets one GPIO pin direction (OUTPUT or INPUT).
 
void gpioSetPinState (uint8_t pin_number, uint8_t pin_state)
 Sets one GPIO output pin state (HIGH or LOW).
 
uint8_t gpioGetPinState (uint8_t pin_number)
 Reads one GPIO pin state and returns 0 or 1.
 
void gpioSetPortMode (uint8_t port_io)
 Sets direction of all GPIO pins using a bitmask.
 
void gpioSetPortState (uint8_t port_state)
 Sets output state of all GPIO pins using a bitmask.
 
void resetDevice ()
 Issues a software reset to the SC16IS752 device.
 
void fifoEnable (SC16IS752_Channel channel, uint8_t fifo_enable)
 Enables or disables FIFO for the selected channel.
 
void fifoReset (SC16IS752_Channel channel, uint8_t rx_fifo)
 Resets RX or TX FIFO for the selected channel.
 
void fifoSetTriggerLevel (SC16IS752_Channel channel, uint8_t rx_fifo, uint8_t length)
 Sets RX or TX FIFO trigger level for interrupt generation.
 
uint8_t fifoAvailableData (SC16IS752_Channel channel)
 Returns number of bytes currently available in RX FIFO.
 
uint8_t fifoAvailableSpace (SC16IS752_Channel channel)
 Returns free space currently available in TX FIFO.
 
void writeByte (SC16IS752_Channel channel, uint8_t val)
 Writes one byte to TX holding register when transmitter is ready.
 
int readByte (SC16IS752_Channel channel)
 Reads one byte from RX holding register, or -1 when no data is available.
 
bool decodeSerialConfig (uint32_t config, uint8_t *data_length, uint8_t *parity_select, uint8_t *stop_length)
 Decodes Arduino SERIAL_* format into data bits, parity, and stop bits.
 

Protected Attributes

bool is_active = false
 
uint8_t device_address_sspin
 
TwoWire * wire_bus
 
SPIClass * spi_bus
 
SPISettings spi_settings {SC16IS752_DEFAULT_SPI_CLOCK, MSBFIRST, SPI_MODE0}
 
uint32_t crystal_freq = SC16IS750_CRYSTCAL_FREQ
 
uint32_t timeout
 
ChannelStream channel_a_stream
 
ChannelStream channel_b_stream
 
int peek_buf [2]
 
uint8_t peek_flag [2]
 
SC16IS752Loggerlogger = nullptr
 

Static Protected Attributes

static constexpr uint8_t SC16IS750_REG_RHR
 Receive Holding Register.
 
static constexpr uint8_t SC16IS750_REG_THR
 Transmit Holding Register.
 
static constexpr uint8_t SC16IS750_REG_IER
 Interrupt Enable Register.
 
static constexpr uint8_t SC16IS750_REG_FCR
 FIFO Control Register.
 
static constexpr uint8_t SC16IS750_REG_IIR
 Interrupt Identification Register.
 
static constexpr uint8_t SC16IS750_REG_LCR
 Line Control Register.
 
static constexpr uint8_t SC16IS750_REG_MCR
 Modem Control Register.
 
static constexpr uint8_t SC16IS750_REG_LSR = 0x05
 Line Status Register.
 
static constexpr uint8_t SC16IS750_REG_MSR
 Modem Status Register.
 
static constexpr uint8_t SC16IS750_REG_SPR = 0x07
 Scratchpad Register.
 
static constexpr uint8_t SC16IS750_REG_TCR
 Transmission Control Register.
 
static constexpr uint8_t SC16IS750_REG_TLR
 Trigger Level Register.
 
static constexpr uint8_t SC16IS750_REG_TXLVL
 TX FIFO Level Register.
 
static constexpr uint8_t SC16IS750_REG_RXLVL
 RX FIFO Level Register.
 
static constexpr uint8_t SC16IS750_REG_IODIR
 GPIO Direction Register.
 
static constexpr uint8_t SC16IS750_REG_IOSTATE
 GPIO State Register.
 
static constexpr uint8_t SC16IS750_REG_IOINTENA
 GPIO Interrupt Enable Register.
 
static constexpr uint8_t SC16IS750_REG_IOCONTROL
 GPIO/IO Control Register.
 
static constexpr uint8_t SC16IS750_REG_EFCR
 Extra Features Control Register.
 
static constexpr uint8_t SC16IS750_REG_DLL = 0x00
 Divisor Latch LSB.
 
static constexpr uint8_t SC16IS750_REG_DLH = 0x01
 Divisor Latch MSB.
 
static constexpr uint8_t SC16IS750_REG_EFR
 Enhanced Features Register.
 
static constexpr uint8_t SC16IS750_REG_XON1
 XON1 flow-control character.
 
static constexpr uint8_t SC16IS750_REG_XON2
 XON2 flow-control character.
 
static constexpr uint8_t SC16IS750_REG_XOFF1
 XOFF1 flow-control character.
 
static constexpr uint8_t SC16IS750_REG_XOFF2
 XOFF2 flow-control character.
 
static constexpr uint8_t SC16IS750_INT_CTS
 CTS change interrupt enable bit.
 
static constexpr uint8_t SC16IS750_INT_RTS
 RTS change interrupt enable bit.
 
static constexpr uint8_t SC16IS750_INT_XOFF
 XOFF interrupt enable bit.
 
static constexpr uint8_t SC16IS750_INT_SLEEP
 Sleep mode interrupt enable bit.
 
static constexpr uint8_t SC16IS750_INT_MODEM
 Modem status interrupt enable bit.
 
static constexpr uint8_t SC16IS750_INT_LINE
 Line status interrupt enable bit.
 
static constexpr uint8_t SC16IS750_INT_THR
 TX holding register interrupt enable bit.
 
static constexpr uint8_t SC16IS750_INT_RHR
 RX holding register interrupt enable bit.
 
static constexpr uint32_t SC16IS750_CRYSTCAL_FREQ
 Default crystal frequency (Hz).
 

Friends

class ChannelStream
 

Detailed Description

Driver for the NXP SC16IS752 dual UART bridge over I2C or SPI.

The SC16IS752 provides two independent UART channels (A and B) and optional GPIO/interrupt capabilities. This class wraps register-level access and exposes:

Construction selects the transport layer:

Typical usage:

SC16IS752 uart(Wire, SC16IS750_I2C_ADDRESS_AD);
uart.channelA().begin(9600);
uart.channelB().begin(115200);
uart.channelA().write('H');
Driver for the NXP SC16IS752 dual UART bridge over I2C or SPI.
Definition SC16IS752.h:170

Optionally, attach a logger with setLogger() to receive debug output.

Member Enumeration Documentation

◆ SC16IS752_Channel

UART channel selector used by channel-specific APIs.

Enumerator
SC16IS752_CHANNEL_A 

UART channel A.

SC16IS752_CHANNEL_B 

UART channel B.

SC16IS752_CHANNEL_BOTH 

Broadcast for global/shared registers.

Member Function Documentation

◆ beginChannel()

void SC16IS752::beginChannel ( SC16IS752_Channel  channel,
uint32_t  baudrate,
uint32_t  config = SC16IS752_DEFAULT_CONFIG 
)
inlineprotected

Initializes a specific UART channel with the given baud rate and serial configuration.

Parameters
channelTarget UART channel.
baudrateUART baud rate.
configArduino-style serial format. Supported values are:
  • SERIAL_5N1
  • SERIAL_6N1
  • SERIAL_7N1
  • SERIAL_8N1 (default)
  • SERIAL_5N2
  • SERIAL_6N2
  • SERIAL_7N2
  • SERIAL_8N2
  • SERIAL_5E1
  • SERIAL_6E1
  • SERIAL_7E1
  • SERIAL_8E1
  • SERIAL_5E2
  • SERIAL_6E2
  • SERIAL_7E2
  • SERIAL_8E2
  • SERIAL_5O1
  • SERIAL_6O1
  • SERIAL_7O1
  • SERIAL_8O1
  • SERIAL_5O2
  • SERIAL_6O2
  • SERIAL_7O2
  • SERIAL_8O2

◆ enableRs485()

void SC16IS752::enableRs485 ( SC16IS752_Channel  channel,
bool  invert_rts 
)
inlineprotected

Enables RS485 mode on the specified channel

Parameters
invert_rtstrue to invert RTS signal, false for normal RTS signal

Member Data Documentation

◆ SC16IS750_CRYSTCAL_FREQ

constexpr uint32_t SC16IS752::SC16IS750_CRYSTCAL_FREQ
staticconstexprprotected
Initial value:
=
1843200UL

Default crystal frequency (Hz).

◆ SC16IS750_INT_CTS

constexpr uint8_t SC16IS752::SC16IS750_INT_CTS
staticconstexprprotected
Initial value:
=
0x80

CTS change interrupt enable bit.

◆ SC16IS750_INT_LINE

constexpr uint8_t SC16IS752::SC16IS750_INT_LINE
staticconstexprprotected
Initial value:
=
0x04

Line status interrupt enable bit.

◆ SC16IS750_INT_MODEM

constexpr uint8_t SC16IS752::SC16IS750_INT_MODEM
staticconstexprprotected
Initial value:
=
0x08

Modem status interrupt enable bit.

◆ SC16IS750_INT_RHR

constexpr uint8_t SC16IS752::SC16IS750_INT_RHR
staticconstexprprotected
Initial value:
=
0x01

RX holding register interrupt enable bit.

◆ SC16IS750_INT_RTS

constexpr uint8_t SC16IS752::SC16IS750_INT_RTS
staticconstexprprotected
Initial value:
=
0x40

RTS change interrupt enable bit.

◆ SC16IS750_INT_SLEEP

constexpr uint8_t SC16IS752::SC16IS750_INT_SLEEP
staticconstexprprotected
Initial value:
=
0x10

Sleep mode interrupt enable bit.

◆ SC16IS750_INT_THR

constexpr uint8_t SC16IS752::SC16IS750_INT_THR
staticconstexprprotected
Initial value:
=
0x02

TX holding register interrupt enable bit.

◆ SC16IS750_INT_XOFF

constexpr uint8_t SC16IS752::SC16IS750_INT_XOFF
staticconstexprprotected
Initial value:
=
0x20

XOFF interrupt enable bit.

◆ SC16IS750_REG_EFCR

constexpr uint8_t SC16IS752::SC16IS750_REG_EFCR
staticconstexprprotected
Initial value:
=
0x0F

Extra Features Control Register.

◆ SC16IS750_REG_EFR

constexpr uint8_t SC16IS752::SC16IS750_REG_EFR
staticconstexprprotected
Initial value:
=
0x02

Enhanced Features Register.

◆ SC16IS750_REG_FCR

constexpr uint8_t SC16IS752::SC16IS750_REG_FCR
staticconstexprprotected
Initial value:
=
0x02

FIFO Control Register.

◆ SC16IS750_REG_IER

constexpr uint8_t SC16IS752::SC16IS750_REG_IER
staticconstexprprotected
Initial value:
=
0x01

Interrupt Enable Register.

◆ SC16IS750_REG_IIR

constexpr uint8_t SC16IS752::SC16IS750_REG_IIR
staticconstexprprotected
Initial value:
=
0x02

Interrupt Identification Register.

◆ SC16IS750_REG_IOCONTROL

constexpr uint8_t SC16IS752::SC16IS750_REG_IOCONTROL
staticconstexprprotected
Initial value:
=
0x0E

GPIO/IO Control Register.

◆ SC16IS750_REG_IODIR

constexpr uint8_t SC16IS752::SC16IS750_REG_IODIR
staticconstexprprotected
Initial value:
=
0x0A

GPIO Direction Register.

◆ SC16IS750_REG_IOINTENA

constexpr uint8_t SC16IS752::SC16IS750_REG_IOINTENA
staticconstexprprotected
Initial value:
=
0x0C

GPIO Interrupt Enable Register.

◆ SC16IS750_REG_IOSTATE

constexpr uint8_t SC16IS752::SC16IS750_REG_IOSTATE
staticconstexprprotected
Initial value:
=
0x0B

GPIO State Register.

◆ SC16IS750_REG_LCR

constexpr uint8_t SC16IS752::SC16IS750_REG_LCR
staticconstexprprotected
Initial value:
=
0x03

Line Control Register.

◆ SC16IS750_REG_MCR

constexpr uint8_t SC16IS752::SC16IS750_REG_MCR
staticconstexprprotected
Initial value:
=
0x04

Modem Control Register.

◆ SC16IS750_REG_MSR

constexpr uint8_t SC16IS752::SC16IS750_REG_MSR
staticconstexprprotected
Initial value:
=
0x06

Modem Status Register.

◆ SC16IS750_REG_RHR

constexpr uint8_t SC16IS752::SC16IS750_REG_RHR
staticconstexprprotected
Initial value:
=
0x00

Receive Holding Register.

◆ SC16IS750_REG_RXLVL

constexpr uint8_t SC16IS752::SC16IS750_REG_RXLVL
staticconstexprprotected
Initial value:
=
0x09

RX FIFO Level Register.

◆ SC16IS750_REG_TCR

constexpr uint8_t SC16IS752::SC16IS750_REG_TCR
staticconstexprprotected
Initial value:
=
0x06

Transmission Control Register.

◆ SC16IS750_REG_THR

constexpr uint8_t SC16IS752::SC16IS750_REG_THR
staticconstexprprotected
Initial value:
=
0x00

Transmit Holding Register.

◆ SC16IS750_REG_TLR

constexpr uint8_t SC16IS752::SC16IS750_REG_TLR
staticconstexprprotected
Initial value:
=
0x07

Trigger Level Register.

◆ SC16IS750_REG_TXLVL

constexpr uint8_t SC16IS752::SC16IS750_REG_TXLVL
staticconstexprprotected
Initial value:
=
0x08

TX FIFO Level Register.

◆ SC16IS750_REG_XOFF1

constexpr uint8_t SC16IS752::SC16IS750_REG_XOFF1
staticconstexprprotected
Initial value:
=
0x06

XOFF1 flow-control character.

◆ SC16IS750_REG_XOFF2

constexpr uint8_t SC16IS752::SC16IS750_REG_XOFF2
staticconstexprprotected
Initial value:
=
0x07

XOFF2 flow-control character.

◆ SC16IS750_REG_XON1

constexpr uint8_t SC16IS752::SC16IS750_REG_XON1
staticconstexprprotected
Initial value:
=
0x04

XON1 flow-control character.

◆ SC16IS750_REG_XON2

constexpr uint8_t SC16IS752::SC16IS750_REG_XON2
staticconstexprprotected
Initial value:
=
0x05

XON2 flow-control character.


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