0
#define InitUART( BRGVal, BRGHighVal )      {                       \
                        UARTTxD = UARTTxDInit;                  \
                        DirUARTTxD = DirOutput;                 \
                        DirUARTRxD = DirInput;                  \
                        SPBRG2 = BRGVal;                        \
                        TXSTA2bits.BRGH = BRGHighVal;           \
                        TXSTA2bits.SYNC = 0;                    \
                        TXSTA2bits.TX9 = 0;                     \
                        TXSTA2bits.TXEN = 1;                    \
                        RCSTA2bits.SPEN = 1;                    \
                        RCSTA2bits.RX9 = 0;                     \
                        IPR3bits.RC2IP = 1;                     \
                        IPR3bits.TX2IP = 0;                     \
                        PIE3bits.TX2IE = 0;                     \
                        PIE3bits.RC2IE = 1;                     \
                        RCSTA2bits.CREN = 0;                    \
                        }

For the last line, i do not understand why clear the RECEIVE ENABLE FLAG i use PIC18LF6722

  • 1
    http://read.pudn.com/downloads153/sourcecode/others/669717/uart.c__.htm: This site indicates setting the CREN flag to 0 clears errors. Then re-enable. – thomas.cloud Jul 11 '14 at 04:15

1 Answers1

0

CREN is the Continuous Receive Enable Bit, which means that in a receive routine, in asynchronous mode, the receive buffer will always clears itself after it's full, allowing a continuous receive of UART characters. In synchronous mode, it's used for other purpose, which you may look at in your PIC'S datasheet.

Jean-francois
  • 316
  • 1
  • 9