Serial Wombat Arduino Library
Public Member Functions | Public Attributes | List of all members
SerialWombatSWUART Class Reference

A class for the Serial Wombat 4B or SW18AB chips which creates a software based UART on the SW18AB. More...

#include <SerialWombatUART.h>

Inheritance diagram for SerialWombatSWUART:
SerialWombatUART SerialWombatPin

Public Member Functions

 SerialWombatSWUART (SerialWombatChip &serialWombatChip)
 
int16_t begin (uint32_t baudRate, uint8_t pin, uint8_t rxPin, uint8_t txPin, uint16_t userMemoryOffset, uint16_t rxLength, uint16_t txLength)
 
int16_t begin (uint32_t baudRate, uint8_t pin, uint8_t rxPin, uint8_t txPin, uint8_t HWinterface)=delete
 This method can't be called for Software UART because it doens't initialize queues in User Data Area. More...
 
size_t write (const uint8_t *buffer, size_t size)
 Write bytes to the SerialWombatUART for Transmit. More...
 
- Public Member Functions inherited from SerialWombatUART
 SerialWombatUART (SerialWombatChip &serialWombat)
 Constructor for the SerialWombatUART class. Only one instance is allowed per SerialWombatChip 4B. More...
 
int16_t begin (uint32_t baudRate, uint8_t pin, uint8_t rxPin, uint8_t txPin, uint8_t HWinterface=1)
 
int available ()
 Queries the SerialWombatUART for number bytes available to read. More...
 
int read ()
 Reads a byte from the SerialWombatUART. More...
 
void flush ()
 Discard all received bytes. More...
 
int peek ()
 Query the SerialWombatUART for the next avaialble byte, but don't remove it from the queue. More...
 
size_t write (uint8_t data)
 Write a byte to the SerialWombatUART for Transmit. More...
 
size_t write (const uint8_t *buffer, size_t size)
 Write bytes to the SerialWombatUART for Transmit. More...
 
int availableForWrite ()
 Queries the SerialWombatUART for the amount of free TX queue space. More...
 
size_t readBytes (char *buffer, size_t length)
 Reads a specified number of bytes from the SerialWombatUART RX queue. More...
 
void setTimeout (long timeout_mS)
 
- Public Member Functions inherited from SerialWombatPin
 SerialWombatPin (SerialWombatChip &serialWombatChip)
 Instantiates a Serial Wombat Pin. More...
 
 SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
 Instantiates a Serial Wombat Pin. More...
 
uint16_t readPublicData ()
 Read the 16 Bit public data associated with this pin. More...
 
void pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
 Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More...
 
void digitalWrite (uint8_t val)
 Set output pin High or Low. More...
 
int digitalRead ()
 Reads the state of the Pin. More...
 
uint16_t writePublicData (uint16_t value)
 Write a 16 bit value to this pin. More...
 
uint8_t pin ()
 Returns the current SW pin number. Used primarily for virtual calls by derived classes. More...
 
uint8_t swPinModeNumber ()
 Returns the Mode number. Used primarily by derived classes to populate packet data. More...
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
 
int16_t disable ()
 Disables the pin mode (if applicable) More...
 

Public Attributes

SerialWombatQueue rxQueue { _sw }
 SerialWombatQueue created on the Serial Wombat chip for data received by the SerialWombatSWUART. More...
 
SerialWombatQueue txQueue { _sw }
 SerialWombatQueue created on the Serial Wombat chip for data to be sent by the SerialWombatSWUART. More...
 

Additional Inherited Members

- Protected Attributes inherited from SerialWombatUART
uint8_t _rxPin = 255
 
uint8_t _txPin = 255
 
uint8_t _baudMarker = 0
 
uint32_t timeout = 5000
 
uint8_t _pinMode = PIN_MODE_UART_RX_TX
 
uint8_t _tx7Command = (uint8_t)SerialWombatCommands::COMMAND_UART0_TX_7BYTES
 
uint8_t _rx7Command = (uint8_t)SerialWombatCommands::COMMAND_UART0_RX_7BYTES
 
- Protected Attributes inherited from SerialWombatPin
uint8_t _pin = 255
 
SerialWombatChip_sw
 
uint8_t _pinMode = 0
 

Detailed Description

A class for the Serial Wombat 4B or SW18AB chips which creates a software based UART on the SW18AB.

A Tutorial video is avaialble:

https://youtu.be/C1FjcaiBYZs

The class inherits from the Arduino Sream class, so functions such as println() can be used once the Software UART is initialized.

Warning
Due to the overhead of querying and retreiving data from the SerialWombatUART, data loss is likely when receiving streams of data greater than the buffer size at higher baud rates.

Multiple instances of this class can be created on the Serial Wombat 18AB chip. This pin mode requires more CPU time than most, particularly for higher baud rate ports. Serial Wombat chip CPU usage should be checked if multiple software uarts are used. Exceeding the available SW18AB CPU resources will cause bit errors in the UART.

A queue in the User Buffer area is allocated for RX and one for TX prior to as part of begin for this mode. Size of these queues should be determined based on system needs. The User needs to ensure that the created queues do not overlap with other structures created in the User Buffer

A full Serial Wombat packet send / receive sequence (8 bytes in each direction) over I2C or the main UART is necessary to query the status of the queues or to read or receive a byte of data.

The protocol becomes more efficient if multiple bytes are read or written using the readBytes or write(const uint8_t* buffer, size_t size) interfaces rather than read() or write(uint8_t data).

The class must be assigned to a pin. This may be either the receive or transmit pin.

Available baud rates are:

Constructor & Destructor Documentation

◆ SerialWombatSWUART()

SerialWombatSWUART::SerialWombatSWUART ( SerialWombatChip serialWombatChip)
inline

Member Function Documentation

◆ begin() [1/2]

int16_t SerialWombatSWUART::begin ( uint32_t  baudRate,
uint8_t  pin,
uint8_t  rxPin,
uint8_t  txPin,
uint16_t  userMemoryOffset,
uint16_t  rxLength,
uint16_t  txLength 
)
inline
Parameters
baudRate300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200
pinThe pin that will host the state machine. This can be either the rxPin or txPin
rxPinThe pin that will receive. All 4 pins on the SW4B may be used. 255 if no receive function is needed
txPinThe pin that will transmit. Valid values for the SW4B are 1-3. 255 if no transmit function is needed
userMemoryoffsetThe offset into User Memory where the software storage queues begin
rxLengthThe length in bytes of the on-chip rx queue (can be 0 if rxPin == 255).
txLengthThe length in bytes of the on-chip tx queue (can be 0 if txPin == 255).

◆ begin() [2/2]

int16_t SerialWombatSWUART::begin ( uint32_t  baudRate,
uint8_t  pin,
uint8_t  rxPin,
uint8_t  txPin,
uint8_t  HWinterface 
)
delete

This method can't be called for Software UART because it doens't initialize queues in User Data Area.

◆ write()

size_t SerialWombatSWUART::write ( const uint8_t *  buffer,
size_t  size 
)
inline

Write bytes to the SerialWombatUART for Transmit.

Parameters
bufferAn array of uint8_t bytes to send
sizethe number of bytes to send
Returns
the number of bytes sent

This function queries the SerialWombatSWUART for avaialble TX buffer space, and sends bytes as buffer space is avaialble. If avaialable buffer space is not sufficient to send the entire array then the function will block and continue trying until the entire message has been sent to the SerialWombatUART transmit queue.

Member Data Documentation

◆ rxQueue

SerialWombatQueue SerialWombatSWUART::rxQueue { _sw }

SerialWombatQueue created on the Serial Wombat chip for data received by the SerialWombatSWUART.

◆ txQueue

SerialWombatQueue SerialWombatSWUART::txQueue { _sw }

SerialWombatQueue created on the Serial Wombat chip for data to be sent by the SerialWombatSWUART.