# serial_hardware2

USART2 hardware control

Author | Stef Mientki, Copyright © 2002..2020, all rights reserved.
Adapted-by | Sebastien Lelong, Rob Hamerling, Rob Jansen
Compiler | 2.5r4

Description

    USART2 hardware control.
    Routines for sending and receiving through the second [E]USART2

Notes

    - See also the notes in serial_hardware library.
           - When the physical locations of pin_TX and pin_RX are configurable for
             a specific PIC, the device file will probably contain names like
             pin_TX2_RC2 and pin_RX2_RC1 and another pair with other pin suffixes.
             Depending for which pair of pins the USART is configured aliases
             without suffixes have to be specified, like:
                 alias  pin_TX2            is  pin_TX2_RC2
                 alias  pin_RX2            is  pin_RX2_RC1
                 alias  pin_TX2_direction  is  pin_TX2_RC2_direction
                 alias  pin_RX2_direction  is  pin_RX2_RC1_direction

Dependencies

- usart2_common

## Summary

### Global variables/contants

### Procedures

- `serial_hw2_init()`
- `serial_hw2_write(byte in data)`
- `serial_hw2_enable()`
- `serial_hw2_data_raw'put(byte in data)`
- `serial_hw2_data'put(byte in data)`
- `serial_hw2_write_word(word in data)`
- `serial_hw2_disable()`

### Functions

- `serial_hw2_data_ready() return bit`
- `serial_hw2_data_available() return bit`
- `serial_hw2_data_raw'get() return byte`
- `serial_hw2_read(byte out data) return bit`
- `serial_hw2_data'get() return byte`

Private

- `_serial_hw2_read(byte out data) return bit`

## API details

### Global variables/contants

### Procedures

- `serial_hw2_init()`

      Title:     Initialize second serial port
      Arguments: (none)
      Returns:   (nothing)

- `serial_hw2_write(byte in data)`

      Title:     Transmit character
      Arguments: Data (byte) to transmit
      Returns:   (nothing)
      Notes:     Hardware transmit buffer must be empty, wait if necessary

- `serial_hw2_enable()`

      Title:     Enable USART2
      Arguments: (none)
      Returns:   (nothing)
      Title:     Re-enable USART after use of serial_hw2_disable()

- `serial_hw2_data_raw'put(byte in data)`

      These are real raw procedures, declared as pseudo variables
      the user is totally responsible for testing the transmit/receive
      flag before using these functions

- `serial_hw2_data'put(byte in data)`

      Title:     Transmit byte
      Arguments: Data (byte) to be transmitted
      Returns:   (nothing)
      Notes:     This pseudo variable allows a language construct like
      serial_hw2_data =
      to transmit a byte to the seial port

- `serial_hw2_write_word(word in data)`

      Title:     Transmit word
      Arguments: Data (word) to transmit
      Returns:   (nothing)
      Notes:     Send word as 2 bytes, Most Significant Byte first.
      See also serial_hw_write()

- `serial_hw2_disable()`

      Title:     Disable USART2
      Arguments: (none)
      Returns:   (nothing)
      Notes:     Allows pins to be used (temporary) for other purposes.
      USART can be enabled again by calling serial_hw2_enable()

### Functions

- `serial_hw2_data_ready() return bit`

      generic (pic-independent) variable to check if transmit buffer is empty

- `serial_hw2_data_available() return bit`

      generic (pic-independent) variable to check if a byte is received

- `serial_hw2_data_raw'get() return byte`

  No documentation found

- `serial_hw2_read(byte out data) return bit`

      Title:     Receive byte
      Arguments: (none)
      Returns:   bit:
        TRUE data available
        FALSE no data available

- `serial_hw2_data'get() return byte`

      Title:     Receive byte
      Arguments: (none)
      Returns:   Data (byte) received
      Notes:     This pseudo variable allows a language construct like
      databyte = serial_hw2_data
      to receive a byte from the serial port into variable 'databyte'

Private

- `_serial_hw2_read(byte out data) return bit`

      Title:     Receive byte
      Arguments: (none)
      Returns:   bit:
        TRUE data available
        FALSE no data available
      Notes:     Using this inline function for serial_hw_data'get saves a stack level
      With overrun error the USART is reset (error(?)byte is returned!)

## Related samples

Here are the list of samples which use this library:

16f19176 | 16f19176_serial_hardware2.jal
16f1947 | 16f1947_serial_hardware2.jal
18f25k22 | 18f25k22_eusart2.jal
18f26j50 | 18f26j50_pps_rx2tx2.jal
18f26k42 | 18f26k42_serial_hardware2.jal
18f27j53 | 18f27j53_pps_rx2tx2.jal
18f27j53 | 18f27j53_xbee_api_rx.jal
18f47q43 | 18f47q43_serial_hardware2.jal
18f6722 | 18f6722_serial_hardware2.jal