AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/at91sam7s/rs485.c
void RS485_Initialize(
    void)
{
    unsigned int pcsr;
    /* Enable the USART0 clock in the Power Management Controller */
    volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;

    pcsr = pPMC->PMC_PCSR;
    pPMC->PMC_PCER = pcsr | (1 << AT91C_ID_US0);

    /* Disable and clear USART0 interrupt
       in AIC Interrupt Disable Command Register */
    volatile AT91PS_AIC pAIC = AT91C_BASE_AIC;
    pAIC->AIC_IDCR = (1 << AT91C_ID_US0);
    pAIC->AIC_ICCR = (1 << AT91C_ID_US0);

    /* enable the peripheral by disabling the pin in the PIO controller */
    *AT91C_PIOA_PDR = AT91C_PA5_RXD0 | AT91C_PA6_TXD0 | AT91C_PA7_RTS0;

    RS485_Interface->US_CR = AT91C_US_RSTRX |   /* Reset Receiver      */
        AT91C_US_RSTTX |        /* Reset Transmitter   */
        AT91C_US_RSTSTA |       /* Clear status register */
        AT91C_US_RXDIS |        /* Receiver Disable    */
        AT91C_US_TXDIS; /* Transmitter Disable */

    RS485_Interface->US_MR = AT91C_US_USMODE_RS485 |    /* RS-485 Mode - RTS auto assert */
        AT91C_US_CLKS_CLOCK |   /* Clock = MCK */
        AT91C_US_CHRL_8_BITS |  /* 8-bit Data  */
        AT91C_US_PAR_NONE |     /* No Parity   */
        AT91C_US_NBSTOP_1_BIT;  /* 1 Stop Bit  */

    /* set the Time Guard to release RTS after x bit times */
    RS485_Interface->US_TTGR = 1;

    /* Receiver Time-out disabled */
    RS485_Interface->US_RTOR = 0;

    /* baud rate */
    RS485_Interface->US_BRGR = MCK / 16 / RS485_Baud;

    RS485_Interface->US_CR = AT91C_US_RXEN |    /* Receiver Enable     */
        AT91C_US_TXEN;  /* Transmitter Enable  */

    return;
}
/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
*              receive mode.
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
Initializes the RS485 hardware and variables, and starts in
receive mode.
Initializes the RS485 hardware and variables and starts in receive mode .
void RS485_Initialize(
    void)
{
    unsigned int pcsr;
    volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;
    pcsr = pPMC->PMC_PCSR;
    pPMC->PMC_PCER = pcsr | (1 << AT91C_ID_US0);
    volatile AT91PS_AIC pAIC = AT91C_BASE_AIC;
    pAIC->AIC_IDCR = (1 << AT91C_ID_US0);
    pAIC->AIC_ICCR = (1 << AT91C_ID_US0);
    *AT91C_PIOA_PDR = AT91C_PA5_RXD0 | AT91C_PA6_TXD0 | AT91C_PA7_RTS0;
    RS485_Interface->US_CR = AT91C_US_RSTRX |   
        AT91C_US_RSTTX |        
        AT91C_US_RSTSTA |       
        AT91C_US_RXDIS |        
        AT91C_US_TXDIS; 
    RS485_Interface->US_MR = AT91C_US_USMODE_RS485 |    
        AT91C_US_CLKS_CLOCK |   
        AT91C_US_CHRL_8_BITS |  
        AT91C_US_PAR_NONE |     
        AT91C_US_NBSTOP_1_BIT;  
    RS485_Interface->US_TTGR = 1;
    RS485_Interface->US_RTOR = 0;
    RS485_Interface->US_BRGR = MCK / 16 / RS485_Baud;
    RS485_Interface->US_CR = AT91C_US_RXEN |    
        AT91C_US_TXEN;  
    return;
}
void RS485_Initialize ( void ) { unsigned int pcsr ; volatile AT91PS_PMC pPMC = AT91C_BASE_PMC ; pcsr = pPMC -> PMC_PCSR ; pPMC -> PMC_PCER = pcsr | ( 1 << AT91C_ID_US0 ) ; volatile AT91PS_AIC pAIC = AT91C_BASE_AIC ; pAIC -> AIC_IDCR = ( 1 << AT91C_ID_US0 ) ; pAIC -> AIC_ICCR = ( 1 << AT91C_ID_US0 ) ; * AT91C_PIOA_PDR = AT91C_PA5_RXD0 | AT91C_PA6_TXD0 | AT91C_PA7_RTS0 ; RS485_Interface -> US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA | AT91C_US_RXDIS | AT91C_US_TXDIS ; RS485_Interface -> US_MR = AT91C_US_USMODE_RS485 | AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT ; RS485_Interface -> US_TTGR = 1 ; RS485_Interface -> US_RTOR = 0 ; RS485_Interface -> US_BRGR = MCK / 16 / RS485_Baud ; RS485_Interface -> US_CR = AT91C_US_RXEN | AT91C_US_TXEN ; return ; }
DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
receive mode.
DESCRIPTION : Initializes the RS485 hardware and variables and starts in receive mode .
/* Enable the USART0 clock in the Power Management Controller */ /* Disable and clear USART0 interrupt
       in AIC Interrupt Disable Command Register */ /* enable the peripheral by disabling the pin in the PIO controller */ /* Reset Receiver      */ /* Reset Transmitter   */ /* Clear status register */ /* Receiver Disable    */ /* Transmitter Disable */ /* RS-485 Mode - RTS auto assert */ /* Clock = MCK */ /* 8-bit Data  */ /* No Parity   */ /* 1 Stop Bit  */ /* set the Time Guard to release RTS after x bit times */ /* Receiver Time-out disabled */ /* baud rate */ /* Receiver Enable     */ /* Transmitter Enable  */