UPER function list

Below is a list of implemented functions and their descriptions. SFP function names are case sensitive. Function IDs (decimal values) are given in the brackets next to every function.

GPIO

setPrimary and setSecondary

Configures pin to primary or secondary function. It is a good practice to configure pin to a secondary function before using the associated module (e.g. analog, pwm, spi, i2c).

Syntax:
setPrimary(int pinID) [01]
setSecondary(int pinID) [02]

Parameters:
int pinID - pin number (0-33).

By default GPIO is always the primary function (unless you are using Debug firmware version). Some pins don't have secondary functions - that is their secondary function is also GPIO. Secondary pin functions are shown in the table below.

:!:Please note, that the pinID in the following table is NOT the same as the number shown on board (or in pinout image):!:

pinID LPC pin Secondary function
0 PIO0_20 GPIO
1 PIO0_2 GPIO
2 PIO1_26 PWM1_2
3 PIO1_27 GPIO
4 PIO1_20 SPI1 SCK
5 PIO0_21 SPI1 MOSI
6 PIO1_23 GPIO
7 PIO1_24 PWM1_0
8 PIO0_7 GPIO
9 PIO1_28 GPIO
10 PIO1_31 GPIO
11 PIO1_21 SPI1 MISO
12 PIO0_8 SPI0 MISO
13 PIO0_9 SPI0 MOSI
14 PIO0_10 SPI0 SCK
15 PIO1_29 GPIO
16 PIO1_19 GPIO
17 PIO1_25 PWM1_1
18 PIO1_16 GPIO
19 PIO0_19 UART TX
20 PIO0_18 UART RX
21 PIO0_17 GPIO
22 PIO1_15 PWM0_2
23 PIO0_23 ADC7
24 PIO0_22 ADC6
25 PIO0_16 ADC5
26 PIO0_15 ADC4
27 PIO1_22 GPIO
28 PIO1_14 PWM0_1
29 PIO1_13 PWM0_0
30 PIO0_14 ADC3
31 PIO0_13 ADC2
32 PIO0_12 ADC1
33 PIO0_11 ADC0

pinMode

Configures GPIO pin mode to input (high-z, pull-up, pull-down) or output.

Syntax:
pinMode(int pinID, int pinMode) [03]

Parameters:
int pinID - pin number (0-33).
int pinMode - pin mode: 0 - input (high Z), 1 - output, 2 - input (pull down), 4 - input (pull up).

digitalWrite

Sets GPIO output high or low.

Syntax:
digitalWrite(int pinID, int value) [04]

Parameters:
int pinID - pin number (0-33).
int value - digital output value: 0 - LOW, 1 - HIGH.

digitalRead

Reads digital state of the GPIO pin.

Syntax:
digitalRead(int pinID) [05]

Parameters:
int pinID - pin number (0-33).

Returns:
digitalRead(int pinID, int value) [05], where the value is 0 (LOW state) or 1 (HIGH state).

attachInterrupt

Attaches GPIO interrupt service to the specified pin. There is a total of 8 interrupts which can be attached to any pin. Interrupts can be configured to trigger at HIGH or LOW state or at RISING, FALLING or both edges. When the interrupt is triggered, device sends message interrupt(int interruptID, int event) [8], where event has the same meaning as the mode.

Syntax:
attachInterrupt(int interruptID, int pinID, int mode, int downtime) [06]

Parameters:
int interruptID - interrupt number (0-7).
int pinID - pin number (0-33).
int mode - interrupt trigger mode: 0-LEVEL LOW, 1-LEVEL HIGH, 2-EDGE CHANGE, 3-EDGE RISE, 4-EDGE FALL.
int downtime - time in miliseconds, how long should the interrupt be inactive after a triggering event (typically 50ms is a good value). Also known as "debounce" parameter. Take extra care when setting very low values of this parameter, because in extreme cases USB stream can be overflooded and make it nearly impossible to communicate with the device.

detachInterrupt

Detaches (disables) the specified GPIO interrupt.

Syntax:
detachInterrupt(int interruptID) [07]

Parameters:
int interruptID - interrupt number (0-7).

pulseIn

Measures a pulse duration on a pin. Is compatible with Arduino command pulseIn (http://arduino.cc/en/Reference/PulseIn). The shortest pulse duration it can measure is two microseconds (trying to measure 1 microsecond length pulse results in receiving pulse width of 2 microseconds).

Syntax:
pulseIn(int pinID, int level, int timeout) [09]

Parameters:
int pinID - pin number (0-33).
int level - level of the pulse (0 - LOW level, 1 - HIGH).
int timeout - number of microseconds to wait until timeout.

Returns:
pulseIn(int pulseWidth) [09], where the pulseWidth is 0 if no pulse was detected during the timeout period or the pulse duration in microseconds.

Analog (ADC)

analogRead

Reads an analog signal value on the specified ADC pin.

Syntax:
analogRead(int analogPinID) [10]

Parameters:
int analogPinID - analog pin number (0-7), corresponds to ADC0-ADC7 pins.

Returns:
analogRead(int analogPinID, int value) [10], where the value is 10 bit ADC read value.

PWM

pwm0_begin and pwm1_begin

Enables and configures PWM module. Each PWM module has 3 channels. PWM signal period (and frequency) is the same for all channels in one PWM module, but the signal high time (and duty cycle) can be different. PWM channels that are in the same module are synchronized.

Syntax:
pwm0_begin(int period) [50]
pwm1_begin(int period) [60]

Parameters:
int period - PWM signal period in microseconds. 16 bit value (1-65536) for PWM0 and 32bit value for PWM1.

pwm0_set and pwm1_set

Sets the high time of the PWM channel.

Syntax:
pwm0_set(int channel, int high_time) [51]
pwm1_set(int channel, int high_time) [61]

Parameters:
int channel - PWM channel number (0-2)
int high_time - PWM signal high time in microseconds. 16 bit value (0-65535) for PWM0 and 32bit value for PWM1. This value should be less than PWM period or undefined behavior might occur.

pwm0_end and pwm1_end

Stops the PWM module.

Syntax:
pwm0_end() [52]
pwm1_end() [62]

SPI

spi0_begin and spi1_begin

Starts and configures SPI module. This function configures the device to master mode. Slave mode is not supported.

Syntax:
spi0_begin(int divider, int mode) [20]
spi1_begin(int divider, int mode) [30]

Parameters:
int divider - SCK signal frequency divider value (1-256). The primary SCK signal frequency is 2MHz.
int mode - standart SPI mode number (0-3) which determines clock polarity and phase (http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Mode_numbers).

spi0_trans and spi1_trans

Executes SPI transaction. User should manually (using GPIO functions) drive slave select line low when executing the transaction.

Syntax:
spi0_trans(byte[] data, int respond) [21]
spi1_trans(byte[] data, int respond) [31]

Parameters:
byte[] data - bytes which will be sent to the slave.
int respond - value which tells if device should send back slave data: 0 - do not send, 1 - send back slave data.

Returns:
spi0_trans(byte[] slaveData) [21] or spi1_trans(byte[] slaveData) [31] if respond value was 1.

spi0_end and spi1_end

Disables the SPI module.

Syntax:
spi0_end() [22]
spi1_end() [32]

I2C

i2c_begin

Initializes I2C module.

Syntax:
i2c_begin() [40]

i2c_trans

Executes I2C MASTER WRITE and MASTER READ transactions.

Syntax:
i2c_trans(int address, byte[] writeData, int readLength) [41]

Parameters:
int address - slave device address.
byte[] writeData - byte array which will be sent to the slave during MASTER WRITE. If array is empty then the MASTER WRITE transaction will be skipped.
int readLength - number of bytes to read during MASTER READ transaction. If readLength is 0 then the MASTER READ transaction will not be executed.

Returns:
i2c_trans(int address, byte[] receivedData), where receivedData is data received durint MASTER READ transaction or i2c_trans(int address, int errorCode) [41] if error occured during one of the transactions.

i2c_end

Disables I2C module.

Syntax:
i2c_end() [42]

System

restart

Performs soft reset. All previous configurations and device states are lost and reset to default. There is an initial 1 second delay before performing the restart sequence, which gives time to disconnect from the virtual COM port and avoid any possible USB glitches on the operating system.

Syntax:
restart() [251]

GetDeviceInfo

Returns device information.

Syntax:
GetDeviceInfo() [255]

Returns:
GetDeviceInfo(int firmwareVersion, byte[] UID, int lpcPartNumber, int lpcBootCodeVersion) [255] message, where:

int firmwareVersion - [31:24] bits are device (firmware) type which is 0x55 (ASCII 'U') for UPER board, [23:16] bits are firmware major version and [15:0] bits are firmware minor version.
byte[] UID - 16 byte long Unique IDentifier of the device (LPC microcontroller).
int lpcPartNumber - device part number of the device (LPC microcontroller).
int lpcBootCodeVersion - device bootload code version of the device (LPC microcontroller).