Datasheet
Soft_UART_Init
416
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6
Prototype
char Soft_UART_Init(unsigned long baud_rate, char inverted);
Returns
- 2 - error, requested baud rate is too low
-
1 - error, requested baud rate is too high
-
0 - successfull initialization
Description
Configures and initializes the software UART module.
Parameters :
-
baud_rate: baud rate to be set. Maximum baud rate depends on the
MCU’s clock and working conditions.
- inverted: inverted output flag. When set to a non-zero value, inverted
logic on output is used.
Software UART routines use Delay_Cyc routine. If requested baud rate is too
low then calculated parameter for calling Delay_Cyc exceeeds Delay_Cyc argu-
ment range.
If requested baud rate is too high then rounding error of Delay_Cyc argument
corrupts Software UART timings.
Requires
Global variables:
- Soft_UART_Rx_Pin: Receiver pin
- Soft_UART_Tx_Pin: Transmiter pin
- Soft_UART_Rx_Pin_Direction: Direction of the Receiver pin
- Soft_UART_Tx_Pin_Direction: Direction of the Transmiter pin
must be defined before using this function.
Example
// Soft UART connections
sbit Soft_UART_Rx_Pin at PIND.B0;
sbit Soft_UART_Tx_Pin at PORTD.B1;
sbit Soft_UART_Rx_Pin_Direction at DDRD.B0;
sbit Soft_UART_Tx_Pin_Direction at DDRD.B1;
// End Soft UART connections
...
// Initialize Software UART communication at 9600 bps.
Soft_UART_Init(9600, 0);