SPI or I2C to UART Bridge

Dependents:   SC16IS750_Test mbed_SC16IS750 Xadow_SC16IS750_Test Xadow_MPU9150AHRS

Embed: (wiki syntax)

« Back to documentation index

SC16IS750_I2C Class Reference

SC16IS750_I2C Class Reference

Class SC16IS750_I2C for a bridge between I2C and a Serial port. More...

#include <SC16IS750.h>

Inherits SC16IS750.

Public Member Functions

 SC16IS750_I2C (I2C *i2c, uint8_t deviceAddress=SC16IS750_DEFAULT_ADDR, PinName rst=NC)
 Create an SC16IS750_I2C object using a specified I2C bus and slaveaddress.
virtual ~SC16IS750_I2C ()
 Destruct SC16IS750_I2C bridge object.
virtual void writeRegister (SC16IS750::RegisterName register_address, char data)
 Write value to internal register.
virtual char readRegister (SC16IS750::RegisterName register_address)
 Read value from internal register.
virtual void writeDataBlock (const char *data, int len)
 Write multiple datavalues to Transmitregister.
virtual void hwReset ()
 Hardware Reset SC16IS750 device.
int readable ()
 Determine if there is a character available to read.
int readableCount ()
 Determine how many characters are available to read.
int writable ()
 Determine if there is space available to write a character.
int writableCount ()
 Determine how much space available for writing characters.
int getc ()
 Read char from UART Bridge.
int putc (int c)
 Write char to UART Bridge.
int printf (const char *format,...)
 Write a formatted string to the UART Bridge.
void writeString (const char *str)
 Write char string to UART Bridge.
void writeBytes (const char *data, int len)
 Write byte array to UART Bridge.
void baud (int baudrate=SC16IS750_DEFAULT_BAUDRATE)
 Set baudrate of the serial port.
void format (int bits=8, Serial::Parity parity=Serial::None, int stop_bits=1)
 Set the transmission format used by the serial port.
void attach (void(*fptr)(void), IrqType type=RxIrq)
 Attach a function to call whenever a serial interrupt is generated.
template<typename T >
void attach (T *tptr, void(T::*mptr)(void), IrqType type=RxIrq)
 Attach a member function to call whenever a serial interrupt is generated.
void send_break ()
 Generate a break condition on the serial line.
void set_break (bool enable=false)
 Set a break condition on the serial line.
void set_flow_control (Flow type=Disabled, PinName flow1=NC, PinName flow2=NC)
 Set the flow control type on the serial port Added for compatibility with Serial Class.
void set_flow_triggers (int resume=TCR_RESUME_DEFAULT, int halt=TCR_HALT_DEFAULT)
 Set the RX FIFO flow control levels This method sets hardware flow control levels.
void set_modem_control ()
 Set the Modem Control register This method sets prescaler, enables TCR and TLR.
bool connected ()
 Check that UART is connected and operational.
void set_fifo_control ()
 FIFO control, sets TX and RX IRQ trigger levels and enables FIFO and save in _config Note FCR[5:4] (=TX_IRQ_LVL) only accessible when EFR[4] is set (enhanced functions enable) Note TLR only accessible when EFR[4] is set (enhanced functions enable) and MCR[2] is set.
void flush ()
 Flush the UART FIFOs while maintaining current FIFO mode.
void ioSetDirection (unsigned char bits)
 Set direction of I/O port pins.
void ioSetState (unsigned char bits)
 Set bits of I/O port pins.
unsigned char ioGetState ()
 Get bits of I/O port pins.
void swReset ()
 Software Reset SC16IS750 device.
void _init ()
 Initialise internal registers Should be in protection section.

Protected Member Functions

virtual int _getc ()
 Needed to implement Stream.
virtual int _putc (int c)
 Needed to implement Stream.
virtual int peek ()
 Needed to implement Stream.

Detailed Description

Class SC16IS750_I2C for a bridge between I2C and a Serial port.

 #include "mbed.h"
 #include "SC16IS750.h"

 I2C i2c(PTE0, PTE1);       //SDA, SCL
 SC16IS750_I2C serial_i2c(&i2c, SC16IS750_DEFAULT_ADDR);

 Serial pc(USBTX,USBRX);

 int main() {
   pc.printf("\nHello World!\n");

   while(1) { 
     serial_i2c.ioSetState(0x00);
     wait(0.5);
     serial_i2c.ioSetState(0xFF); 
     wait(0.5); 
     serial_i2c.putc('*');   
     pc.putc('*');                
   }
 }

Definition at line 811 of file SC16IS750.h.


Constructor & Destructor Documentation

SC16IS750_I2C ( I2C *  i2c,
uint8_t  deviceAddress = SC16IS750_DEFAULT_ADDR,
PinName  rst = NC 
)

Create an SC16IS750_I2C object using a specified I2C bus and slaveaddress.

Create a SC16IS750_I2C object for a bridge between I2C and a Serial port.

Parameters:
I2C&i2c the I2C port to connect to
chardeviceAddress the address of the SC16IS750
rstPinname for Reset pin (active low) Optional, Default = NC
I2C&i2c the I2C port to connect to
chardeviceAddress the I2C slave address of the SC16IS750
rstPinname for Reset pin (active low) Optional, Default = NC

Definition at line 774 of file SC16IS750.cpp.

~SC16IS750_I2C (  ) [virtual]

Destruct SC16IS750_I2C bridge object.

Parameters:
none
Returns:
none

Definition at line 800 of file SC16IS750.cpp.


Member Function Documentation

virtual int _getc (  ) [protected, virtual, inherited]

Needed to implement Stream.

Read char from UART Bridge. Acts in the same manner as 'Serial.read()'.

Parameters:
none
Returns:
char read or -1 if no data available.

Definition at line 661 of file SC16IS750.h.

void _init (  ) [inherited]

Initialise internal registers Should be in protection section.

Public for testing purposes If initialisation fails this method does not return.

Parameters:
none
Returns:
none

Definition at line 233 of file SC16IS750.cpp.

virtual int _putc ( int  c ) [protected, virtual, inherited]

Needed to implement Stream.

Write char to UART Bridge. Blocking when no free space in FIFO

Parameters:
valuechar to be written
Returns:
value written

Definition at line 672 of file SC16IS750.h.

void attach ( T *  tptr,
void(T::*)(void)  mptr,
IrqType  type = RxIrq 
) [inherited]

Attach a member function to call whenever a serial interrupt is generated.

Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called
typeWhich serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
Returns:
none

Definition at line 490 of file SC16IS750.h.

void attach ( void(*)(void)  fptr,
IrqType  type = RxIrq 
) [inherited]

Attach a function to call whenever a serial interrupt is generated.

Parameters:
fptrA pointer to a void function, or 0 to set as none
typeWhich serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
void baud ( int  baudrate = SC16IS750_DEFAULT_BAUDRATE ) [inherited]

Set baudrate of the serial port.

Parameters:
baudinteger baudrate (4800, 9600 etc)
Returns:
none

Definition at line 49 of file SC16IS750.cpp.

bool connected (  ) [inherited]

Check that UART is connected and operational.

Parameters:
none
Returns:
bool true when connected, false otherwise

Definition at line 369 of file SC16IS750.cpp.

void flush (  ) [inherited]

Flush the UART FIFOs while maintaining current FIFO mode.

Parameters:
none
Returns:
none

Definition at line 333 of file SC16IS750.cpp.

void format ( int  bits = 8,
Serial::Parity  parity = Serial::None,
int  stop_bits = 1 
) [inherited]

Set the transmission format used by the serial port.

Parameters:
bitsThe number of bits in a word (5-8; default = 8)
parityThe parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None)
stop_bitsThe number of stop bits (1 or 2; default = 1)
Returns:
none

Definition at line 70 of file SC16IS750.cpp.

int getc (  ) [inherited]

Read char from UART Bridge.

Acts in the same manner as 'Serial.read()'.

Parameters:
none
Returns:
char read or -1 if no data available.

Definition at line 439 of file SC16IS750.cpp.

void hwReset (  ) [virtual]

Hardware Reset SC16IS750 device.

This method is only functional when the Reset pin has been declared and is also connected

Parameters:
none
Returns:
none

This method is only available when the Reset pin has been declared and is also connected

Parameters:
none
Returns:
none

Implements SC16IS750.

Definition at line 888 of file SC16IS750.cpp.

unsigned char ioGetState (  ) [inherited]

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.

Parameters:
none
Returns:
bits Bitpattern for I/O (1= bit set, 0 = bit cleared)

Definition at line 612 of file SC16IS750.cpp.

void ioSetDirection ( unsigned char  bits ) [inherited]

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.

Parameters:
bitsBitpattern for I/O (1=output, 0=input)
Returns:
none

Definition at line 592 of file SC16IS750.cpp.

void ioSetState ( unsigned char  bits ) [inherited]

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.

Parameters:
bitsBitpattern for I/O (1= set output bit, 0 = clear output bit)
Returns:
none

Definition at line 602 of file SC16IS750.cpp.

virtual int peek (  ) [protected, virtual, inherited]

Needed to implement Stream.

Definition at line 679 of file SC16IS750.h.

int printf ( const char *  format,
  ... 
) [inherited]

Write a formatted string to the UART Bridge.

Blocking when no free space in FIFO

Parameters:
formatA printf-style format string, followed by the variables to use in formatting the string.
int putc ( int  value ) [inherited]

Write char to UART Bridge.

Blocking when no free space in FIFO

Parameters:
valuechar to be written
Returns:
value written

Definition at line 454 of file SC16IS750.cpp.

int readable (  ) [inherited]

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).

Returns:
1 if there is a character available to read, 0 otherwise

Definition at line 385 of file SC16IS750.cpp.

int readableCount (  ) [inherited]

Determine how many characters are available to read.

This is data that's already arrived and stored in the receive buffer (which holds 64 chars).

Returns:
int Characters available to read

Definition at line 402 of file SC16IS750.cpp.

char readRegister ( SC16IS750::RegisterName  register_address ) [virtual]

Read value from internal register.

Parameters:
registerAddressThe address of the Register (enum RegisterName)
Returns:
char The 8bit value read from the register

Implements SC16IS750.

Definition at line 824 of file SC16IS750.cpp.

void send_break (  ) [inherited]

Generate a break condition on the serial line.

Parameters:
none
Returns:
none
none

Definition at line 116 of file SC16IS750.cpp.

void set_break ( bool  enable = false ) [inherited]

Set a break condition on the serial line.

Parameters:
enablebreak condition
Returns:
none

Definition at line 134 of file SC16IS750.cpp.

void set_fifo_control (  ) [inherited]

FIFO control, sets TX and RX IRQ trigger levels and enables FIFO and save in _config Note FCR[5:4] (=TX_IRQ_LVL) only accessible when EFR[4] is set (enhanced functions enable) Note TLR only accessible when EFR[4] is set (enhanced functions enable) and MCR[2] is set.

FIFO control, sets TX and RX trigger levels and enables FIFO and save in _config Note FCR[5:4] (=TX_IRQ_LVL) only accessible when EFR[4] is set (enhanced functions enable) Note TLR only accessible when EFR[4] is set (enhanced functions enable) and MCR[2] is set.

Parameters:
none
Returns:
none

Definition at line 300 of file SC16IS750.cpp.

void set_flow_control ( Flow  type = Disabled,
PinName  flow1 = NC,
PinName  flow2 = NC 
) [inherited]

Set the flow control type on the serial port Added for compatibility with Serial Class.

SC16IS750 supports only Flow, Pins can not be selected. This method sets hardware flow control levels. SC16IS750 supports XON/XOFF, but this is not implemented.

Parameters:
typethe flow control type (Disabled, RTS, CTS, RTSCTS)
flow1the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
flow2the second flow control pin (CTS for RTSCTS)
Returns:
none

SC16IS750 supports only Flow, Pins can not be selected. This method sets hardware flow control. SC16IS750 supports XON/XOFF, but this is not implemented.

Parameters:
typethe flow control type (Disabled, RTS, CTS, RTSCTS)
flow1the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS) - NOT USED
flow2the second flow control pin (CTS for RTSCTS) - NOT USED
Returns:
none

Definition at line 156 of file SC16IS750.cpp.

void set_flow_triggers ( int  resume = TCR_RESUME_DEFAULT,
int  halt = TCR_HALT_DEFAULT 
) [inherited]

Set the RX FIFO flow control levels This method sets hardware flow control levels.

SC16IS750 supports XON/XOFF, but this is not implemented. Should be called BEFORE Auto RTS is enabled.

Parameters:
resumetrigger level to resume transmission (0..15, meaning 0-60 with a granularity of 4)
halttrigger level to resume transmission (0..15, meaning 0-60 with granularity of 4)
Returns:
none

Definition at line 193 of file SC16IS750.cpp.

void set_modem_control (  ) [inherited]

Set the Modem Control register This method sets prescaler, enables TCR and TLR.

Parameters:
none
Returns:
none

Definition at line 214 of file SC16IS750.cpp.

void swReset (  ) [inherited]

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.

Parameters:
none
Returns:
none

Definition at line 623 of file SC16IS750.cpp.

int writable (  ) [inherited]

Determine if there is space available to write a character.

Returns:
1 if there is a space for a character to write, 0 otherwise

Definition at line 410 of file SC16IS750.cpp.

int writableCount (  ) [inherited]

Determine how much space available for writing characters.

This considers data that's already stored in the transmit buffer (which holds 64 chars).

Returns:
int character space available to write

Definition at line 427 of file SC16IS750.cpp.

void writeBytes ( const char *  data,
int  len 
) [inherited]

Write byte array to UART Bridge.

Blocking when no free space in FIFO

Parameters:
*databyte array to be written
lennumber of bytes to write
Returns:
none

Definition at line 533 of file SC16IS750.cpp.

void writeDataBlock ( const char *  data,
int  len 
) [virtual]

Write multiple datavalues to Transmitregister.

More Efficient implementation than writing individual bytes Assume that previous check confirmed that the FIFO has sufficient free space to store the data Pure virtual, must be declared in derived class.

Parameters:
char*databytes The pointer to the block of data
lenThe number of bytes to write
Returns:
none

Implements SC16IS750.

Definition at line 849 of file SC16IS750.cpp.

void writeRegister ( SC16IS750::RegisterName  register_address,
char  data 
) [virtual]

Write value to internal register.

Parameters:
registerAddressThe address of the Register (enum RegisterName)
dataThe 8bit value to write
Returns:
none

Implements SC16IS750.

Definition at line 810 of file SC16IS750.cpp.

void writeString ( const char *  str ) [inherited]

Write char string to UART Bridge.

Blocking when no free space in FIFO

Parameters:
*strchar string to be written
Returns:
none

Definition at line 471 of file SC16IS750.cpp.