PreviousNext
Help > Software > The <platform.h> Library for C.impl > Communications
Communications

int spiOpen(int channel, int mode, int baudrate)

Open a SPI channel for communication. Will return 0 is successful, or a negative value result otherwise.

ELLO 1A has only one SPI channel, which is shared among all SPI devices (including the SD card), so the only acceptable parameter for channel number, is 2.

The ‘mode’ parameter specifies the SPI mode between 0 and 3. The port is always initialised for exchange of data words with length of 8 bits.

The ‘baudrate‘ parameter defines the speed of the transfer.

 

int spiClose(int channel)

Close a SPI channel. Will return 0 is successful, or a negative value result otherwise.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 2.

 

unsigned char spiByte(int channel, unsigned char data)

Perform data exchange of a single byte through an open SPI channel. A SPI transfer involves simultaneous transmit and receive operation on every transfer.

It is important to mention, that the chip select signal for the SPI device participating on the other end of the communication, must be set low prior to the actual transfer taking place, and set back high when the transfer is complete.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 2.

 

void spiBlock(int channel, unsigned char *buffer, size_t len)

Perform data exchange of data block of ‘len’ bytes through an open SPI channel. The data to be transmitted should be preloaded in the buffer, and the received data is returned on its place.

It is important to mention, that the chip select signal for the SPI device participating on the other end of the communication, must be set low prior to the actual transfer taking place, and set back high when the transfer is complete.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 2.

 

int comOpen(int channel, int mode, int protocol, int baudrate, int rx_buffer_size)

Open an asynchronous serial communication (aka. UART) channel.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 1.

The parameter “mode” defines the specific hardware configuration for the UART. It is a bitmask with bits directly written into the PIC32’s UART registers. There are many bits, however not all of them apply to the ELLO 1A system.

The default value for “mode” is 0. Below are those which could be safely used with the ELLO:

UART_ENABLE_HIGH_SPEED                   0x00000008    // Enables high-speed range of the UART

UART_INVERT_RECEIVE_POLARITY        0x00000010    // Inverts polarity of data from the (RX) pin

UART_ENABLE_LOOPBACK                      0x00000040    // Enables UART TX-to-RX Loop-back mode

UART_ENABLE_IRDA                                 0x00001000    // Enable the IrDA encoder/decoder

UART_INVERT_TRANSMIT_POLARITY    0x20000000    // Inverts the polarity of data on the (TX) pin

The parameter “protocol” is another bitmask written directly into the PIC32’s registers.

Its default value is 0, corresponding to a default protocol 8 data bits, 1 stop bit, no parity.

The bits usable in the ELLO are shown below:

UART_DATA_SIZE_8_BITS     0x0000    // Sets the data transfer size to 8-bits per frame

UART_STOP_BITS_1               0x0000    // Enables generation of 1 stop bit per frame (default)

UART_PARITY_NONE             0x0000    // Disables parity bit generation

UART_DATA_SIZE_9_BITS     0x0006    // Sets the data transfer size to 9-bits per frame

UART_PARITY_ODD               0x0004    // Enables parity bit generation for odd parity

UART_PARITY_EVEN              0x0002    // Enables parity bit generation for even parity

UART_STOP_BITS_2               0x0001    // Enables generation of 2 stop bits per frame

 

int comClose(int channel)

Close a serial port.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 1.

 

int comBuff(int channel)

Return the number of currently buffered bytes for the serial channel. Does not remove anything from the buffer.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 1.

 

int comPeek(int channel)

Return the ASCII code of the first character to be received without removing it from the buffer. If the buffer is empty, will return -1.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 1.

 

void comTx(int channel, int bytes, unsigned char *buffer)

Send one or more bytes to an open serial channel. The parameter “buffer” is a pointer to the first byte, and the number of bytes to be sent is defined by the parameter “bytes”.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 1.

 

int comRx(int channel, int bytes, unsigned char *buffer)

Receive one or more bytes from an open serial channel. The parameter “buffer” is a pointer to the first byte of an available memory buffer with sufficient size, and the maximum number of bytes to be received is defined by the parameter “bytes”. Every read byte is removed from the internal COM reception buffer. The function will terminate if there are more expected bytes, but there are no more in the reception buffer.

The function returns the number of actually received bytes.

The only acceptable parameter for ‘channel’ in ELLO 1A, is 1.

 

void comRxCall(int channel, int bytes, void (*intHandler)(void))

Set a reception handler for serial channel. The handler function gets executed every time when there are more than the specified number of bytes in the reception buffer.

It is an important detail to note that the handler function should be supplied in its calling format, i.e. func(), not func.

As an example:

            comRxCall( 1, 8, msgRd() );   // call the msgRd() function every time when there are 8 or more
                                                               // bytes in the COM1 reception buffer

The only acceptable parameter for ‘channel’ in ELLO 1A, is 1.

 

int i2cInit(int baudrate)

Initialise the I2C bus with given baudrate in bps. Speeds up to 1,000,000 bps are supported. The function will return the actual baudrate to which the bus has been initialised.

ELLO 1A supports only single master mode for I2C operation. This means that the system expects it will be the only one who drives the SCL (clock) line on the bus.

The i2cInit() function is not required for the normal operation of the I2C bus. It is only needed if the bus is to be initialised with a baudrate different from the default 100 kbps.

 

void i2cStart(void)

Send “Start” signal on the I2C bus.

 

void i2cRepStart(void)

Send “Repeated Start” signal on the I2C bus.

 

void i2cStop(void)

Send “Stop” signal on the I2C bus.

 

int i2cSend(unsigned char data8)

Send a byte on the I2C bus. Will return 0 in case the byte was acknowledged by the receiver, or 1 in otherwise.

 

unsigned char i2cRecv(int stop)

Receive a byte from the I2C bus. When parameter stop is 0, more bytes are expected to be read. A value 1 will indicate that the current is the last byte in a frame.