Example of UART-DMA transfers taken form the npx cmsis driver libary

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

UART Public Functions

UART Public Functions
[UART]

Functions

void UART_Init (LPC_UART_TypeDef *UARTx, UART_CFG_Type *UART_ConfigStruct)
 Initializes the UARTx peripheral according to the specified parameters in the UART_ConfigStruct.
void UART_DeInit (LPC_UART_TypeDef *UARTx)
 De-initializes the UARTx peripheral registers to their default reset values.
void UART_ConfigStructInit (UART_CFG_Type *UART_InitStruct)
 Fills each UART_InitStruct member with its default value:

  • 9600 bps
  • 8-bit data
  • 1 Stopbit
  • None Parity.

void UART_SendByte (LPC_UART_TypeDef *UARTx, uint8_t Data)
 Transmit a single data through UART peripheral.
uint8_t UART_ReceiveByte (LPC_UART_TypeDef *UARTx)
 Receive a single data from UART peripheral.
uint32_t UART_Send (LPC_UART_TypeDef *UARTx, uint8_t *txbuf, uint32_t buflen, TRANSFER_BLOCK_Type flag)
 Send a block of data via UART peripheral.
uint32_t UART_Receive (LPC_UART_TypeDef *UARTx, uint8_t *rxbuf,\uint32_t buflen, TRANSFER_BLOCK_Type flag)
 Receive a block of data via UART peripheral.
void UART_ForceBreak (LPC_UART_TypeDef *UARTx)
 Force BREAK character on UART line, output pin UARTx TXD is forced to logic 0.
void UART_IntConfig (LPC_UART_TypeDef *UARTx, UART_INT_Type UARTIntCfg, FunctionalState NewState)
 Enable or disable specified UART interrupt.
uint8_t UART_GetLineStatus (LPC_UART_TypeDef *UARTx)
 Get current value of Line Status register in UART peripheral.
uint32_t UART_GetIntId (LPC_UART_TypeDef *UARTx)
 Get Interrupt Identification value.
FlagStatus UART_CheckBusy (LPC_UART_TypeDef *UARTx)
 Check whether if UART is busy or not.
void UART_FIFOConfig (LPC_UART_TypeDef *UARTx, UART_FIFO_CFG_Type *FIFOCfg)
 Configure FIFO function on selected UART peripheral.
void UART_FIFOConfigStructInit (UART_FIFO_CFG_Type *UART_FIFOInitStruct)
 Fills each UART_FIFOInitStruct member with its default value:

  • FIFO_DMAMode = DISABLE
  • FIFO_Level = UART_FIFO_TRGLEV0
  • FIFO_ResetRxBuf = ENABLE
  • FIFO_ResetTxBuf = ENABLE
  • FIFO_State = ENABLE.

void UART_ABCmd (LPC_UART_TypeDef *UARTx, UART_AB_CFG_Type *ABConfigStruct,\FunctionalState NewState)
 Start/Stop Auto Baudrate activity.
void UART_ABClearIntPending (LPC_UART_TypeDef *UARTx, UART_ABEO_Type ABIntType)
 Clear Autobaud Interrupt Pending.
void UART_TxCmd (LPC_UART_TypeDef *UARTx, FunctionalState NewState)
 Enable/Disable transmission on UART TxD pin.
void UART_IrDAInvtInputCmd (LPC_UART_TypeDef *UARTx, FunctionalState NewState)
 Enable or disable inverting serial input function of IrDA on UART peripheral.
void UART_IrDACmd (LPC_UART_TypeDef *UARTx, FunctionalState NewState)
 Enable or disable IrDA function on UART peripheral.
void UART_IrDAPulseDivConfig (LPC_UART_TypeDef *UARTx, UART_IrDA_PULSE_Type PulseDiv)
 Configure Pulse divider for IrDA function on UART peripheral.
void UART_FullModemForcePinState (LPC_UART1_TypeDef *UARTx, UART_MODEM_PIN_Type Pin,\UART1_SignalState NewState)
 Force pin DTR/RTS corresponding to given state (Full modem mode)
void UART_FullModemConfigMode (LPC_UART1_TypeDef *UARTx, UART_MODEM_MODE_Type Mode,\FunctionalState NewState)
 Configure Full Modem mode for UART peripheral.
uint8_t UART_FullModemGetStatus (LPC_UART1_TypeDef *UARTx)
 Get current status of modem status register.
void UART_RS485Config (LPC_UART1_TypeDef *UARTx, UART1_RS485_CTRLCFG_Type *RS485ConfigStruct)
 Configure UART peripheral in RS485 mode according to the specified parameters in the RS485ConfigStruct.
void UART_RS485ReceiverCmd (LPC_UART1_TypeDef *UARTx, FunctionalState NewState)
 Enable/Disable receiver in RS485 module in UART1.
uint32_t UART_RS485Send (LPC_UART1_TypeDef *UARTx, uint8_t *pDatFrm,\uint32_t size, uint8_t ParityStick)
 Send data on RS485 bus with specified parity stick value (9-bit mode).
void UART_RS485SendSlvAddr (LPC_UART1_TypeDef *UARTx, uint8_t SlvAddr)
 Send Slave address frames on RS485 bus.
uint32_t UART_RS485SendData (LPC_UART1_TypeDef *UARTx, uint8_t *pData, uint32_t size)
 Send Data frames on RS485 bus.

Function Documentation

void UART_ABClearIntPending ( LPC_UART_TypeDef *  UARTx,
UART_ABEO_Type  ABIntType 
)

Clear Autobaud Interrupt Pending.

Parameters:
[in]UARTxUART peripheral selected, should be

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[in]ABIntTypetype of auto-baud interrupt, should be:

  • UART_AUTOBAUD_INTSTAT_ABEO: End of Auto-baud interrupt
  • UART_AUTOBAUD_INTSTAT_ABTO: Auto-baud time out interrupt
Returns:
none

Definition at line 967 of file lpc17xx_uart.c.

void UART_ABCmd ( LPC_UART_TypeDef *  UARTx,
UART_AB_CFG_Type ABConfigStruct,
\FunctionalState  NewState 
)

Start/Stop Auto Baudrate activity.

Parameters:
[in]UARTxUART peripheral selected, should be

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[in]ABConfigStructA pointer to UART_AB_CFG_Type structure that contains specified information about UART auto baudrate configuration
[in]NewStateNew State of Auto baudrate activity, should be:

  • ENABLE: Start this activity
  • DISABLE: Stop this activity Note: Auto-baudrate mode enable bit will be cleared once this mode completed.
    Returns:
    none

Definition at line 899 of file lpc17xx_uart.c.

FlagStatus UART_CheckBusy ( LPC_UART_TypeDef *  UARTx )

Check whether if UART is busy or not.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
Returns:
RESET if UART is not busy, otherwise return SET.

Definition at line 788 of file lpc17xx_uart.c.

void UART_ConfigStructInit ( UART_CFG_Type UART_InitStruct )

Fills each UART_InitStruct member with its default value:

  • 9600 bps
  • 8-bit data
  • 1 Stopbit
  • None Parity.

Parameters:
[in]UART_InitStructPointer to a UART_CFG_Type structure which will be initialized.
Returns:
None

Definition at line 442 of file lpc17xx_uart.c.

void UART_DeInit ( LPC_UART_TypeDef *  UARTx )

De-initializes the UARTx peripheral registers to their default reset values.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
Returns:
None

Definition at line 392 of file lpc17xx_uart.c.

void UART_FIFOConfig ( LPC_UART_TypeDef *  UARTx,
UART_FIFO_CFG_Type FIFOCfg 
)

Configure FIFO function on selected UART peripheral.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[in]FIFOCfgPointer to a UART_FIFO_CFG_Type Structure that contains specified information about FIFO configuration
Returns:
none

Definition at line 809 of file lpc17xx_uart.c.

void UART_FIFOConfigStructInit ( UART_FIFO_CFG_Type UART_FIFOInitStruct )

Fills each UART_FIFOInitStruct member with its default value:

  • FIFO_DMAMode = DISABLE
  • FIFO_Level = UART_FIFO_TRGLEV0
  • FIFO_ResetRxBuf = ENABLE
  • FIFO_ResetTxBuf = ENABLE
  • FIFO_State = ENABLE.

Parameters:
[in]UART_FIFOInitStructPointer to a UART_FIFO_CFG_Type structure which will be initialized.
Returns:
None

Definition at line 873 of file lpc17xx_uart.c.

void UART_ForceBreak ( LPC_UART_TypeDef *  UARTx )

Force BREAK character on UART line, output pin UARTx TXD is forced to logic 0.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
Returns:
None

Definition at line 632 of file lpc17xx_uart.c.

void UART_FullModemConfigMode ( LPC_UART1_TypeDef *  UARTx,
UART_MODEM_MODE_Type  Mode,
\FunctionalState  NewState 
)

Configure Full Modem mode for UART peripheral.

Parameters:
[in]UARTxLPC_UART1 (only)
[in]ModeFull Modem mode, should be:

  • UART1_MODEM_MODE_LOOPBACK: Loop back mode.
  • UART1_MODEM_MODE_AUTO_RTS: Auto-RTS mode.
  • UART1_MODEM_MODE_AUTO_CTS: Auto-CTS mode.
[in]NewStateNew State of this mode, should be:

  • ENABLE: Enable this mode.
  • DISABLE: Disable this mode.
    Returns:
    none

Definition at line 1158 of file lpc17xx_uart.c.

void UART_FullModemForcePinState ( LPC_UART1_TypeDef *  UARTx,
UART_MODEM_PIN_Type  Pin,
\UART1_SignalState  NewState 
)

Force pin DTR/RTS corresponding to given state (Full modem mode)

Parameters:
[in]UARTxLPC_UART1 (only)
[in]PinPin that NewState will be applied to, should be:

  • UART1_MODEM_PIN_DTR: DTR pin.
  • UART1_MODEM_PIN_RTS: RTS pin.
[in]NewStateNew State of DTR/RTS pin, should be:

  • INACTIVE: Force the pin to inactive signal.
  • ACTIVE: Force the pin to active signal.
    Returns:
    none

Definition at line 1118 of file lpc17xx_uart.c.

uint8_t UART_FullModemGetStatus ( LPC_UART1_TypeDef *  UARTx )

Get current status of modem status register.

Parameters:
[in]UARTxLPC_UART1 (only)
Returns:
Current value of modem status register Note: The return value of this function must be ANDed with each member UART_MODEM_STAT_type enumeration to determine current flag status corresponding to each modem flag status. Because some flags in modem status register will be cleared after reading, the next reading modem register could not be correct. So this function used to read modem status register in one time only, then the return value used to check all flags.

Definition at line 1204 of file lpc17xx_uart.c.

uint32_t UART_GetIntId ( LPC_UART_TypeDef *  UARTx )

Get Interrupt Identification value.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
Returns:
Current value of UART UIIR register in UART peripheral.

Definition at line 773 of file lpc17xx_uart.c.

uint8_t UART_GetLineStatus ( LPC_UART_TypeDef *  UARTx )

Get current value of Line Status register in UART peripheral.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
Returns:
Current value of Line Status register in UART peripheral. Note: The return value of this function must be ANDed with each member in UART_LS_Type enumeration to determine current flag status corresponding to each Line status type. Because some flags in Line Status register will be cleared after reading, the next reading Line Status register could not be correct. So this function used to read Line status register in one time only, then the return value used to check all flags.

Definition at line 750 of file lpc17xx_uart.c.

void UART_Init ( LPC_UART_TypeDef *  UARTx,
UART_CFG_Type UART_ConfigStruct 
)

Initializes the UARTx peripheral according to the specified parameters in the UART_ConfigStruct.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[in]UART_ConfigStructPointer to a UART_CFG_Type structure that contains the configuration information for the specified UART peripheral.
Returns:
None

Definition at line 186 of file lpc17xx_uart.c.

void UART_IntConfig ( LPC_UART_TypeDef *  UARTx,
UART_INT_Type  UARTIntCfg,
FunctionalState  NewState 
)

Enable or disable specified UART interrupt.

Parameters:
[in]UARTxUART peripheral selected, should be

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[in]UARTIntCfgSpecifies the interrupt flag, should be one of the following:

  • UART_INTCFG_RBR : RBR Interrupt enable
  • UART_INTCFG_THRE : THR Interrupt enable
  • UART_INTCFG_RLS : RX line status interrupt enable
  • UART1_INTCFG_MS : Modem status interrupt enable (UART1 only)
  • UART1_INTCFG_CTS : CTS1 signal transition interrupt enable (UART1 only)
  • UART_INTCFG_ABEO : Enables the end of auto-baud interrupt
  • UART_INTCFG_ABTO : Enables the auto-baud time-out interrupt
[in]NewStateNew state of specified UART interrupt type, should be:

  • ENALBE: Enable this UART interrupt type.
  • DISALBE: Disable this UART interrupt type.
Returns:
None

Definition at line 669 of file lpc17xx_uart.c.

void UART_IrDACmd ( LPC_UART_TypeDef *  UARTx,
FunctionalState  NewState 
)

Enable or disable IrDA function on UART peripheral.

Parameters:
[in]UARTxUART peripheral selected, should be LPC_UART3 (only)
[in]NewStateNew state of IrDA function, should be:

  • ENABLE: Enable this function.
  • DISABLE: Disable this function.
Returns:
none

Definition at line 1056 of file lpc17xx_uart.c.

void UART_IrDAInvtInputCmd ( LPC_UART_TypeDef *  UARTx,
FunctionalState  NewState 
)

Enable or disable inverting serial input function of IrDA on UART peripheral.

Parameters:
[in]UARTxUART peripheral selected, should be LPC_UART3 (only)
[in]NewStateNew state of inverting serial input, should be:

  • ENABLE: Enable this function.
  • DISABLE: Disable this function.
Returns:
none

Definition at line 1032 of file lpc17xx_uart.c.

void UART_IrDAPulseDivConfig ( LPC_UART_TypeDef *  UARTx,
UART_IrDA_PULSE_Type  PulseDiv 
)

Configure Pulse divider for IrDA function on UART peripheral.

Parameters:
[in]UARTxUART peripheral selected, should be LPC_UART3 (only)
[in]PulseDivPulse Divider value from Peripheral clock, should be one of the following:

  • UART_IrDA_PULSEDIV2 : Pulse width = 2 * Tpclk
  • UART_IrDA_PULSEDIV4 : Pulse width = 4 * Tpclk
  • UART_IrDA_PULSEDIV8 : Pulse width = 8 * Tpclk
  • UART_IrDA_PULSEDIV16 : Pulse width = 16 * Tpclk
  • UART_IrDA_PULSEDIV32 : Pulse width = 32 * Tpclk
  • UART_IrDA_PULSEDIV64 : Pulse width = 64 * Tpclk
  • UART_IrDA_PULSEDIV128 : Pulse width = 128 * Tpclk
  • UART_IrDA_PULSEDIV256 : Pulse width = 256 * Tpclk
Returns:
none

Definition at line 1088 of file lpc17xx_uart.c.

uint32_t UART_Receive ( LPC_UART_TypeDef *  UARTx,
uint8_t *  rxbuf,
\uint32_t  buflen,
TRANSFER_BLOCK_Type  flag 
)

Receive a block of data via UART peripheral.

Parameters:
[in]UARTxSelected UART peripheral used to send data, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[out]rxbufPointer to Received buffer
[in]buflenLength of Received buffer
[in]flagFlag mode, should be NONE_BLOCKING or BLOCKING
Returns:
Number of bytes received

Note: when using UART in BLOCKING mode, a time-out condition is used via defined symbol UART_BLOCKING_TIMEOUT.

Definition at line 581 of file lpc17xx_uart.c.

uint8_t UART_ReceiveByte ( LPC_UART_TypeDef *  UARTx )

Receive a single data from UART peripheral.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
Returns:
Data received

Definition at line 486 of file lpc17xx_uart.c.

void UART_RS485Config ( LPC_UART1_TypeDef *  UARTx,
UART1_RS485_CTRLCFG_Type RS485ConfigStruct 
)

Configure UART peripheral in RS485 mode according to the specified parameters in the RS485ConfigStruct.

Parameters:
[in]UARTxLPC_UART1 (only)
[in]RS485ConfigStructPointer to a UART1_RS485_CTRLCFG_Type structure that contains the configuration information for specified UART in RS485 mode.
Returns:
None

Definition at line 1222 of file lpc17xx_uart.c.

void UART_RS485ReceiverCmd ( LPC_UART1_TypeDef *  UARTx,
FunctionalState  NewState 
)

Enable/Disable receiver in RS485 module in UART1.

Parameters:
[in]UARTxLPC_UART1 (only)
[in]NewStateNew State of command, should be:

  • ENABLE: Enable this function.
  • DISABLE: Disable this function.
Returns:
None

Definition at line 1294 of file lpc17xx_uart.c.

uint32_t UART_RS485Send ( LPC_UART1_TypeDef *  UARTx,
uint8_t *  pDatFrm,
\uint32_t  size,
uint8_t  ParityStick 
)

Send data on RS485 bus with specified parity stick value (9-bit mode).

Parameters:
[in]UARTxLPC_UART1 (only)
[in]pDatFrmPointer to data frame.
[in]sizeSize of data.
[in]ParityStickParity Stick value, should be 0 or 1.
Returns:
None

Definition at line 1311 of file lpc17xx_uart.c.

uint32_t UART_RS485SendData ( LPC_UART1_TypeDef *  UARTx,
uint8_t *  pData,
uint32_t  size 
)

Send Data frames on RS485 bus.

Parameters:
[in]UARTxLPC_UART1 (only)
[in]pDataPointer to data to be sent.
[in]sizeSize of data frame to be sent.
Returns:
None

Definition at line 1349 of file lpc17xx_uart.c.

void UART_RS485SendSlvAddr ( LPC_UART1_TypeDef *  UARTx,
uint8_t  SlvAddr 
)

Send Slave address frames on RS485 bus.

Parameters:
[in]UARTxLPC_UART1 (only)
[in]SlvAddrSlave Address.
Returns:
None

Definition at line 1337 of file lpc17xx_uart.c.

uint32_t UART_Send ( LPC_UART_TypeDef *  UARTx,
uint8_t *  txbuf,
uint32_t  buflen,
TRANSFER_BLOCK_Type  flag 
)

Send a block of data via UART peripheral.

Parameters:
[in]UARTxSelected UART peripheral used to send data, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[in]txbufPointer to Transmit buffer
[in]buflenLength of Transmit buffer
[in]flagFlag used in UART transfer, should be NONE_BLOCKING or BLOCKING
Returns:
Number of bytes sent.

Note: when using UART in BLOCKING mode, a time-out condition is used via defined symbol UART_BLOCKING_TIMEOUT.

Definition at line 516 of file lpc17xx_uart.c.

void UART_SendByte ( LPC_UART_TypeDef *  UARTx,
uint8_t  Data 
)

Transmit a single data through UART peripheral.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[in]DataData to transmit (must be 8-bit long)
Returns:
None

Definition at line 461 of file lpc17xx_uart.c.

void UART_TxCmd ( LPC_UART_TypeDef *  UARTx,
FunctionalState  NewState 
)

Enable/Disable transmission on UART TxD pin.

Parameters:
[in]UARTxUART peripheral selected, should be:

  • LPC_UART0: UART0 peripheral
    • LPC_UART1: UART1 peripheral
    • LPC_UART2: UART2 peripheral
    • LPC_UART3: UART3 peripheral
[in]NewStateNew State of Tx transmission function, should be:

  • ENABLE: Enable this function
  • DISABLE: Disable this function
    Returns:
    none

Definition at line 990 of file lpc17xx_uart.c.