Demo entry 6327822

sci5_init

   

Submitted by Alter on Nov 25, 2016 at 03:43
Language: C. Code size: 3.9 kB.

void sci5_init(void)
{
        SYSTEM.PRCR.WORD = 0xA502;          /* Enables writing to the registers */
    MSTP(SCI5) = 0;                     /* SCI1 module stop state is canceled */
    SYSTEM.PRCR.WORD = 0xA500;          /* Disables writing to the registers */
       
        /* ---- SCI interrupt request is disabled ---- */
    IEN(SCI5,ERI5) = 0;                 /* SCI5.ERI5 interrupt request is disabled */
    IEN(SCI5,RXI5) = 0;                 /* SCI5.RXI5 interrupt request is disabled */
    IEN(SCI5,TXI5) = 0;                 /* SCI5.TXI5 interrupt request is disabled */
    IEN(SCI5,TEI5) = 0;                 /* SCI5.TEI5 interrupt request is disabled */
       
        /* ---- Initialization of SCI ---- */
    SCI5.SCR.BYTE = 0x00;               /* Disable transmission and reception */
    while (0x00 != (SCI5.SCR.BYTE & 0xF0))
    {
        /* Confirm that bit is actually 0 */
    }
       
        MPC.PWPR.BIT.B0WI   = 0;            /* Writing to the PFSWE bit is enabled */
    MPC.PWPR.BIT.PFSWE  = 1;            /* Writing to the PFS register is enabled */
    MPC.PC2PFS.BIT.PSEL = 0x0A;         /* RXD5 */
    MPC.PC3PFS.BIT.PSEL = 0x0A;         /* TXD5 */
    MPC.PWPR.BIT.PFSWE  = 0;            /* Writing to the PFS register is disabled */
    MPC.PWPR.BIT.B0WI   = 1;            /* Writing to the PFSWE bit is disabled */
    PORTC.PMR.BIT.B2    = 1;            /* PC2/RXD5: Use pin as I/O port for peripheral function */
       
        SCI5.SCR.BIT.CKE = 0;               /* Select an On-chip baud rate generator to the clock source */
        //----------------------------------
        SCI5.SMR.BYTE    = 0x00;            /* Clock source: PCLKB */
    //  n = 0                                                   /* Communications mode: Asynchronous mode */
       
        SCI5.SMR.BIT.PE  = 0;                                                                  
        //----------------------------------                                                                           
    SCI5.SCMR.BYTE   = 0xF2;            /* Smart card interface mode: serial communications interface mode */
                                        /* Data invert: Not inverted */
                                        /* Data transfer direction: LSB-first */
    SCI5.SEMR.BYTE = 0x00;              /* Base Clock Select: Selects 16 base clock cycles for 1-bit period */
                                        /* Noise cancellation function for the RXDn input signal: Disabled */
    SCI5.BRR         = 80;              /* 19.34 = (25MHz/(64*2^(-1)*9600bps))-1 */
//      n and S: Determined by the SMR setting listed in the following table.
       
        /* ---- Initialization of SCI interrupt ---- */
    IPR(SCI5,   )  = 1;                 /* SCI5 interrupt priority level is 1 */
    IR(SCI5,RXI5)  = 0;                 /* SCI5.RXI5 interrupt request is cleared (Edge interrupt) */
    IR(SCI5,TXI5)  = 0;                 /* SCI5.TXI5 interrupt request is cleared (Edge interrupt) */
       
        /* ==== Start to transmit and receive ==== */
        SCI5.SCR.BYTE |= 0xF4;              /* Enable TE, TIE, TEIE, RE, RIE */
    PORTC.PMR.BIT.B3 = 1;               /* PC3/TXD1: Use pin as I/O port for peripheral function */
        PORTC.PMR.BIT.B2 = 1;               /* PC2/RXD1: Use pin as I/O port for peripheral function */
    IEN(SCI5,ERI5) = 1;                 /* Enable ERI5 interrupt request */
    IEN(SCI5,RXI5) = 1;                 /* Enable RXI5 interrupt request */
    IEN(SCI5,TXI5) = 1;                 /* Disable TXI5 interrupt request */
       
        //-----------------------------------
        SCI5.SCR.BIT.TIE = 0;
        SCI5.SCR.BIT.TE  = 0;
        SCI5.SCR.BIT.RIE = 1;
        SCI5.SCR.BIT.RE  = 0;
        //-----------------------------------
       
        //IR(SCI5,RXI5)  = 1;
}
Parsed in 0.009 secon

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).