User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
425
Software UART Library
The mikroC PRO for PIC32 provides routines for implementing Software UART communication. These routines are
hardware independent and can be used with any MCU.
The Software UART Library provides easy communication with other devices via the RS232 protocol.
Important: The Software UART library implements time-based activities, so interrupts need to be disabled when using it.
Library Routines
- Soft_UART_Init
- Soft_UART_Read
- Soft_UART_Write
- Soft_UART_Break
Soft_UART_Init
Prototype
char Soft_UART_Init(unsigned int *port, unsigned int rx, unsigned int tx,
unsigned long baud_rate, unsigned int inverted);
Description Congures and initializes the software UART module.
Software UART routines use Delay_Cyc routine. If requested baud rate is too low then calculated
parameter for calling Delay_Cyc exceeds Delay_Cyc argument range.
If requested baud rate is too high then rounding error of Delay_Cyc argument corrupts Software
UART timings.
Parameters - port: software UART port address
- rx: receiver pin
- tx: transmiter pin
- baud_rate: requested baudrate. Maximum baud rate depends on the MCU’s clock and working
conditions
- inverted: if set to non-zero value, indicates inverted logic on output
Returns - 2 - error, requested baud rate is too low
- 1 - error, requested baud rate is too high
- 0 - successful initialization
Requires Nothing.
Example This will initialize software UART and establish the communication at 9600 bps:
char error;
...
error = Soft_UART_Init(&PORTF, 4, 5, 14400, 0); // Initialize Soft UART
at 14400 bps
Notes The Software UART library implements time-based activities, so interrupts need to be disabled when
using it.