PreviousNext
Help > RITTLE FOR THE PIC32MZ MICROCONTROLLER > Work with Communication Interfaces > enable
enable

Format:                                                                        

enable (text_interface, text_parameters [, @func_callback() ] );

Enable specified communication interface. Enabling the interface automatically configures the needed I/O ports.

There are several interfaces currently supported in Rittle:

SPI1           - SPI interface on ports 49 (SCLK), 50 (MISO), 51 (MOSI).

Additionally, when initialised in slave mode, port 58 is automatically assigned as digital input, and monitored during execution. The call back function gets executed when a low level on the port has been detected. The user’s function must monitor itself for the port going back to high, before exit.

SPI2           - SPI interface on ports 29 (SCLK), 22 (MISO), 23 (MOSI).

Additionally, when initialised in slave mode, port 28 is automatically assigned as digital input, and monitored during execution. The call back function gets executed when a low level on the port has been detected. The user’s function must monitor itself for the port going back to high, before exit.

IIC1            - I2C interface on ports 43 (SDA) and 44 (SCL).

IIC2            - I2C interface on ports 41 (SDA) and 42 (SCL).

The same port as COM3, so only one of them can be used at a time.

COM0       - System console.  Serial UART interface on pins 17 (Rx) and 18 (Tx)

COM1       - Serial UART interface on pins 52 (Rx) and 53 (Tx)

COM2       - Serial UART interface on pins 56 (Rx) and 57 (Tx)

COM3       - Serial UART interface on pins 41 (Rx) and 42 (Tx)

The same port as IIC2, so only one of them can be used at a time.

COM4       - Serial UART interface on pins 11 (Rx) and 13 (Tx)

COM5       - Serial UART interface on pins 14 (Rx) and 16 (Tx)

The second parameter in the ‘enable’ function defines specific options for the selected interface. It is also given in text form like the first one with interface name.

An optional third parameter specifies a call back function that is executed when a data word is received. The requirements toward the call back function are very strict – it must have no input or output parameters.

Call back functions are always allowed for UARTs but only allowed in slave roles for the other interfaces.

 

For SPI interfaces the format is:

“role (M or S) [, baudrate ] [, SPI mode (0 or 1 or 2 or 3), data word length (8 or 16 or 32) ] ]” [, @rx_callback() ]

The role could be either M(aster) or S(lave).

Baudrate values are only valid in master mode and can be between 1 and 100,000,000 bits per second.

If not specified, the default SPI mode is 0, and the default data word length is 8 bits. New data word length can be defined only if SPI mode is specified too.

Examples for SPI interface:

enable “SPI1”, “M, 12000000”;              ‘ SPI master working at 12MHz in mode 0

enable “SPI2”, “S, 3, 16”, @rx_spi();     ‘ SPI master in mode 3 with 16-bit data
‘ word and a call back function executed
‘ on every received data word

 

For I2C interfaces the parameters have the following format:

“role (M or S) [, baudrate ]” [, @rx_callback() ]

The role could be either M(aster) or S(lave), followed by baudrate (only valid in Master only) value between 1 and 5,000,000 bits per second.

Example for enabling the I2C interface:

enable “IIC1”, “M, 400000”;

 

The UART serial interfaces implement the RS232 protocol and have this format:

"baudrate [, data bits (8 or 9) parity (N or E or O)  stop bits (1 or 2) ]"
[, @rx_callback() ]

Baudrate value can be between 1 and 25,000,000 bits per second.

If not specified, the default protocol parameters are 8 data bits, no parity, 1 stop bit. Other options for parity include E(ven) or O(dd).

Examples for enabling and configuration of UART interface:

enable “UART1”, “115200, 8N1”, @rx1;          ‘ will execute the callback function
‘ rx1() on every received data byte

enable “UART4”, “9600”;   ‘ default protocol 8N1 and without call back function