Robobo
usart.h File Reference
#include "../chip.h"
#include <stdint.h>

Go to the source code of this file.

Macros

#define USART_MODE_ASYNCHRONOUS   (US_MR_CHRL_8_BIT | US_MR_PAR_NO)
 
#define USART_MODE_IRDA   (AT91C_US_USMODE_IRDA | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_FILTER)
 
#define AT91C_US_USMODE_SPIM   0xE
 
#define US_SPI_CPOL_0   (0x0<<16)
 
#define US_SPI_CPHA_0   (0x0<<8)
 
#define US_SPI_CPOL_1   (0x1<<16)
 
#define US_SPI_CPHA_1   (0x1<<8)
 
#define US_SPI_BPMODE_0   (US_SPI_CPOL_0|US_SPI_CPHA_1)
 
#define US_SPI_BPMODE_1   (US_SPI_CPOL_0|US_SPI_CPHA_0)
 
#define US_SPI_BPMODE_2   (US_SPI_CPOL_1|US_SPI_CPHA_1)
 
#define US_SPI_BPMODE_3   (US_SPI_CPOL_1|US_SPI_CPHA_0)
 

Functions

void USART_Configure (Usart *usart, uint32_t mode, uint32_t baudrate, uint32_t masterClock)
 Configures an USART peripheral with the specified parameters. More...
 
uint32_t USART_GetStatus (Usart *usart)
 Get present status.
 
void USART_EnableIt (Usart *usart, uint32_t mode)
 Enable interrupt.
 
void USART_DisableIt (Usart *usart, uint32_t mode)
 Disable interrupt.
 
void USART_SetTransmitterEnabled (Usart *usart, uint8_t enabled)
 Enables or disables the transmitter of an USART peripheral. More...
 
void USART_SetReceiverEnabled (Usart *usart, uint8_t enabled)
 Enables or disables the receiver of an USART peripheral. More...
 
void USART_Write (Usart *usart, uint16_t data, volatile uint32_t timeOut)
 Sends one packet of data through the specified USART peripheral. This function operates synchronously, so it only returns when the data has been actually sent. More...
 
uint8_t USART_WriteBuffer (Usart *usart, void *buffer, uint32_t size)
 Sends the contents of a data buffer through the specified USART peripheral. This function returns immediately (1 if the buffer has been queued, 0 otherwise); poll the ENDTX and TXBUFE bits of the USART status register to check for the transfer completion. More...
 
uint16_t USART_Read (Usart *usart, volatile uint32_t timeOut)
 Reads and return a packet of data on the specified USART peripheral. This function operates asynchronously, so it waits until some data has been received. More...
 
uint8_t USART_ReadBuffer (Usart *usart, void *buffer, uint32_t size)
 Reads data from an USART peripheral, filling the provided buffer until it becomes full. This function returns immediately with 1 if the buffer has been queued for transmission; otherwise 0. More...
 
uint8_t USART_IsDataAvailable (Usart *usart)
 Returns 1 if some data has been received and can be read from an USART; otherwise returns 0. More...
 
void USART_SetIrdaFilter (Usart *pUsart, uint8_t filter)
 Sets the filter value for the IRDA demodulator. More...
 
void USART_PutChar (Usart *usart, uint8_t c)
 Sends one packet of data through the specified USART peripheral. This function operates synchronously, so it only returns when the data has been actually sent. More...
 
uint32_t USART_IsRxReady (Usart *usart)
 Return 1 if a character can be read in USART.
 
uint8_t USART_GetChar (Usart *usart)
 Reads and returns a character from the USART. More...
 

Detailed Description

Purpose

This module provides several definitions and methods for using an USART peripheral.

Usage
  1. Enable the USART peripheral clock in the PMC.
  2. Enable the required USART PIOs (see pio.h).
  3. Configure the UART by calling USART_Configure.
  4. Enable the transmitter and/or the receiver of the USART using USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
  5. Send data through the USART using the USART_Write and USART_WriteBuffer methods.
  6. Receive data from the USART using the USART_Read and USART_ReadBuffer functions; the availability of data can be polled with USART_IsDataAvailable.
  7. Disable the transmitter and/or the receiver of the USART with USART_SetTransmitterEnabled and USART_SetReceiverEnabled.

Macro Definition Documentation

#define AT91C_US_USMODE_SPIM   0xE

SPI mode

#define USART_MODE_ASYNCHRONOUS   (US_MR_CHRL_8_BIT | US_MR_PAR_NO)

USART modes

This section lists several common operating modes for an USART peripheral.

Modes

  • USART_MODE_ASYNCHRONOUS
  • USART_MODE_IRDABasic asynchronous mode, i.e. 8 bits no parity.
#define USART_MODE_IRDA   (AT91C_US_USMODE_IRDA | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_FILTER)

IRDA mode

Function Documentation

void USART_Configure ( Usart usart,
uint32_t  mode,
uint32_t  baudrate,
uint32_t  masterClock 
)

Configures an USART peripheral with the specified parameters.

Parameters
usartPointer to the USART peripheral to configure.
modeDesired value for the USART mode register (see the datasheet).
baudrateBaudrate at which the USART should operate (in Hz).
masterClockFrequency of the system master clock (in Hz).
uint8_t USART_GetChar ( Usart usart)

Reads and returns a character from the USART.

Note
This function is synchronous (i.e. uses polling).
Parameters
usartPointer to an USART peripheral.
Returns
Character received.
uint8_t USART_IsDataAvailable ( Usart usart)

Returns 1 if some data has been received and can be read from an USART; otherwise returns 0.

Parameters
usartPointer to an Usart instance.
void USART_PutChar ( Usart usart,
uint8_t  c 
)

Sends one packet of data through the specified USART peripheral. This function operates synchronously, so it only returns when the data has been actually sent.

Parameters
usartPointer to an USART peripheral.
cCharacter to send
uint16_t USART_Read ( Usart usart,
volatile uint32_t  timeOut 
)

Reads and return a packet of data on the specified USART peripheral. This function operates asynchronously, so it waits until some data has been received.

Parameters
usartPointer to an USART peripheral.
timeOutTime out value (0 -> no timeout).
uint8_t USART_ReadBuffer ( Usart usart,
void *  buffer,
uint32_t  size 
)

Reads data from an USART peripheral, filling the provided buffer until it becomes full. This function returns immediately with 1 if the buffer has been queued for transmission; otherwise 0.

Parameters
usartPointer to an USART peripheral.
bufferPointer to the buffer where the received data will be stored.
sizeSize of the data buffer (in bytes).
void USART_SetIrdaFilter ( Usart pUsart,
uint8_t  filter 
)

Sets the filter value for the IRDA demodulator.

Parameters
pUsartPointer to an Usart instance.
filterFilter value.
void USART_SetReceiverEnabled ( Usart usart,
uint8_t  enabled 
)

Enables or disables the receiver of an USART peripheral.

Parameters
usartPointer to an USART peripheral
enabledIf true, the receiver is enabled; otherwise it is disabled.
void USART_SetTransmitterEnabled ( Usart usart,
uint8_t  enabled 
)

Enables or disables the transmitter of an USART peripheral.

Parameters
usartPointer to an USART peripheral
enabledIf true, the transmitter is enabled; otherwise it is disabled.
void USART_Write ( Usart usart,
uint16_t  data,
volatile uint32_t  timeOut 
)

Sends one packet of data through the specified USART peripheral. This function operates synchronously, so it only returns when the data has been actually sent.

Parameters
usartPointer to an USART peripheral.
dataData to send including 9nth bit and sync field if necessary (in the same format as the US_THR register in the datasheet).
timeOutTime out value (0 = no timeout).
uint8_t USART_WriteBuffer ( Usart usart,
void *  buffer,
uint32_t  size 
)

Sends the contents of a data buffer through the specified USART peripheral. This function returns immediately (1 if the buffer has been queued, 0 otherwise); poll the ENDTX and TXBUFE bits of the USART status register to check for the transfer completion.

Parameters
usartPointer to an USART peripheral.
bufferPointer to the data buffer to send.
sizeSize of the data buffer (in bytes).