====== Wireless function list ====== All of these functions (except for interrupt and return functions) are sent from wUPER router to wUPER nodes. In general, they are very similar to the UPER functions except that they all have an additional deviceAddress parameter which tells to which device the function should be sent (in case of transmitting a message) or from which device it came from (in case of receiving a message). ====== 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 deviceAddress, int pinID) [1]'' \\ ''**setSecondary**(int deviceAddress, int pinID) [2]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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. ^ 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 deviceAddress, int pinID, int pinMode) [3]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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 deviceAddress, int pinID, int value) [4]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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 deviceAddress, int pinID) [5]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''int **pinID**'' - pin number (0-33). \\ Returns: \\ ''**digitalRead**(int deviceAddress, int pinID, int value) [5]'', 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 7 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. Syntax: \\ ''**attachInterrupt**(int deviceAddress, int interruptID, int pinID, int mode) [6]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''int **interruptID**'' - interrupt number (0-6). \\ ''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. Returns: \\ When the GPIO interrupt is triggered, the device sends ''**interrupt**(int deviceAddress, 8, int interruptID, int mode) [8]'' message (see [[wuper:1:wirelessfunctions#interrupt|interrupt]]). ===== detachInterrupt ===== Detaches (disables) the specified GPIO interrupt. Syntax: \\ ''**detachInterrupt**(int interruptID) [7]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''int **interruptID**'' - interrupt number (0-6). ===== pulseIn ===== Measures a pulse duration on a pin. Is compatible with Arduino command [[http://arduino.cc/en/Reference/PulseIn|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 deviceAddress, int pinID, int level, int timeout) [9]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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 deviceAddress, int pulseWidth) [9]'', 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 deviceAddress, int analogPinID) [10]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''int **analogPinID**'' - analog pin number (0-7), corresponds to ADC0-ADC7 pins. Returns: \\ ''**analogRead**(int deviceAddress, int analogPinID, int value) [10]'', where 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 deviceAddress, int period) [50]'' \\ ''**pwm1_begin**(int deviceAddress, int period) [60]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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 deviceAddress, int channel, int high_time) [51]'' \\ ''**pwm1_set**(int deviceAddress, int channel, int high_time) [61]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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**(int deviceAddress) [52]'' \\ ''**pwm1_end**(int deviceAddress) [62]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. ====== SPI ====== ===== spi0_begin ===== Starts and configures SPI module. This function configures the device to master mode. Slave mode is not supported. Syntax: \\ ''**spi0_begin**(int deviceAddress, int divider, int mode) [20]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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 ===== Executes SPI transaction. User should manually (using GPIO functions) drive slave select line low when executing the transaction. Syntax: \\ ''**spi0_trans**(int deviceAddress, byte[] data, int respond) [21]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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**(int deviceAddress, byte[] slaveData) [21]'' if respond value was 1. ===== spi0_end ===== Disables the SPI module. Syntax: \\ ''**spi0_end**(int deviceAddress) [22]'' ====== I2C ====== ===== i2c_begin ===== Initializes I2C module. Syntax: \\ ''**i2c_begin**(int deviceAddress) [40]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. ===== i2c_trans ===== Executes I2C MASTER WRITE and MASTER READ transactions. Syntax: \\ ''**i2c_trans**(int deviceAddress, int address, byte[] writeData, int readLength) [41]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''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 deviceAddress, byte[] receivedData) [41]'', where receivedData is data received during MASTER READ transaction or ''**i2c_trans**(int deviceAddress, int errorCode) [41]'' if error occurred during one of the transactions. ===== i2c_end ===== Disables I2C module. Syntax: \\ ''**i2c_end**(int deviceAddress) [42]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. ====== System ====== ===== sleep ===== Puts the node device to sleep for the specified duration or until a system interrupt, whichever happens first. Note that this command is only available when the node device is in power saving mode (link FIXME). Syntax: \\ ''**sleep**(int deviceAddress, int sleepTimeout) [254]'' Parameters: \\ ''int **deviceAddress**'' - the target device address. \\ ''int **sleepTimeout**'' - the maximum number of seconds to sleep. ===== interrupt ===== This message is sent from node to router and indicates that a specific system interrupt has happened. Syntax: \\ ''**interrupt**(int deviceAddress, int interruptType, int param1, int param2) [8]'' Parameters: \\ ''int **deviceAddress**'' - the source device address. \\ ''int **interruptType**'' - the type of system interrupt (see table below). \\ ''int **param1**'' - first parameter (see table below). \\ ''int **param2**'' - second parameter (see table below). ^ Interrupt name ^ interruptType ^ param1 ^ param2 ^ | RESET INTERRUPT | 1 | LPC SYSRSTSTAT register | 0 | | WAKEUP INTERRUPT | 5 | 0 | 0 | | GPIO INTERRUPT | 8 | GPIO interruptID | GPIO interrupt type (mode) |