DTR, RTS and serial status

… visits
Parent Previous Next

You can skip most of this handling for a simple USB-only measurement device. Use it when you need to know that a terminal is ready, or when your PIC bridges USB to a physical UART.

Read changes sent by the PC

Call USB_GetEvents() in your main program. Test each relevant bit of USB_LastEvents separately, because several changes can happen together. Use the following events when your application needs to act on serial settings:

Event

State to read

Application use

USB_EV_LINE

USB_LineCoding[0..6]

Apply requested serial settings to a UART, or record them.

USB_EV_DTR_RTS

USB_LineState

Bit 0 is DTR; bit 1 is RTS. Update your readiness logic or UART control outputs if needed.

USB_EV_BREAK

USB_BreakMs

Handle the host's break request.

The seven line-coding bytes are:

Bytes

Contents

0–3

Baud rate, unsigned 32-bit, low byte first

4

Stop bits: 0 = one; 1 = one-and-a-half; 2 = two

5

Parity: 0 none; 1 odd; 2 even; 3 mark; 4 space

6

Data bits: 5, 6, 7, 8 or 16

In interrupt mode, first take a consistent copy of all the bytes you need; see shared-data handling. Your own code must act on these events and set any UART pins. Choosing RTS or flow control in the terminal does not add hardware flow control to the firmware.


For break, USB_BreakMs=0 means stop break, 65535 means indefinite break, and other values request milliseconds. The library records the request; a UART bridge must generate and time the physical break itself.

Send serial status back to the PC

Call USB_CDC_Notify(pState As Word) when you need to report carrier, ring, break or UART errors from the PIC to the host. This is separate from the host-to-PIC DTR/RTS state.

Bit

Meaning

0

Receive carrier / DCD

1

Transmit carrier / DSR

2

Break state

3

Ring signal

4

Framing error

5

Parity error

6

Overrun error

For example, USB_CDC_Notify(3) records DCD and DSR as asserted. Use that only if it represents your application's state. Bits above 6 are ignored. In CDC mode, USB_OK means the status was recorded for notification, not that the PC has already received it. Changes can merge before the host polls; this is not a queue for application messages. Outside CDC mode the call returns USB_NOT_SUPPORTED.


A USB-only measurement device can simply exchange commands and readings without inventing serial carrier or UART errors. Add line-state and notification handling when your particular application needs it.

See also

Created with the Personal Edition of HelpNDoc: Easily convert your WinHelp HLP help files to CHM with HelpNDoc's step-by-step guide