AnsweredAssumed Answered

[MPC5604P] UART scanf function

Question asked by eschick on Feb 23, 2017
Latest reply on Mar 1, 2017 by eschick

Hi  all,

I'm trying to receive a character send from Putty on my MPC5604P device. I'm using this Example Example MPC5604P PinToggleStationery CW210 from Martin Kovar.

The printf function is working properly, but scanf doesn't work. It seems that UART doesn't receive anything. The UARTSR[DRF] remains zero and the BDRM Register remains empty.

Here is my configuration:

#define BAUDRATE 115200

 

void Init_LINFlex_1(void)
{
    /* enter INIT mode */
    LINFLEX_1.LINCR1.R = 0x0081; /* SLEEP=0, INIT=1 */

    /* wait for the INIT mode */
    while (0x1000 != (LINFLEX_1.LINSR.R & 0xF000)) {}

    /* configure pads */
    SIU.PCR[35].R = 0x0E04;     /* Configure pad PC3 for AF3 func: LIN1TX */
    SIU.PCR[60].R = 0x0100;     /* Configure pad PD12 for LIN1RX */

    /* configure for UART mode */
    LINFLEX_1.UARTCR.R = 0x0001; /* set the UART bit first to be able to write the other bits */

    LINFLEX_1.UARTCR.R = 0x0033; /* 8bit data, no parity, Tx and Rx enabled, UART mode */
                                 /* Transmit buffer size = 1 (TDFL = 0 */
                                 /* Receive buffer size = 1 (RDFL = 0) */
    LINFLEX_1.UARTSR.B.SZF = 1;    // clear SZF flag
    LINFLEX_1.UARTSR.B.DRF = 1; // clear data reception completed flag
    //LINFLEX_1.LINIER.B.DRIE = 1;    //enable received interrupt

switch(BAUDRATE) {
    case 19200:
        #if defined(CORE_CLOCK_64MHz)
            LINFLEX_1.LINFBRR.R = 5;
            LINFLEX_1.LINIBRR.R = 208;
        #elif defined(CORE_CLOCK_40MHz)
            LINFLEX_1.LINFBRR.R = 4;
            LINFLEX_1.LINIBRR.R = 130;
        #endif
    break;
    case 115200:
        #if defined(CORE_CLOCK_64MHz)
            LINFLEX_1.LINFBRR.R = 12;
            LINFLEX_1.LINIBRR.R = 34;
        #elif defined(CORE_CLOCK_40MHz)
            LINFLEX_1.LINFBRR.R = ;
            LINFLEX_1.LINIBRR.R = ;
        #endif
    break;
    default:    //9600
        #if defined(CORE_CLOCK_64MHz)
            LINFLEX_1.LINFBRR.R = 11;
            LINFLEX_1.LINIBRR.R = 416;
        #elif defined(CORE_CLOCK_40MHz)
            LINFLEX_1.LINFBRR.R = ;
            LINFLEX_1.LINIBRR.R = ;
        #endif
    break;
}

Compared to the example I'm using the LINFlex1 module and the other Pads.

int32_t ReceiveData(char * const pBuf)
{
    int32_t rx_data;
        /* wait for DRF */
    while (1 != LINFLEX_1.UARTSR.B.DRF) {}  /* Wait for data reception completed flag */
    /* wait for RMB */
    while (1 != LINFLEX_1.UARTSR.B.RMB) {}  /* Wait for Release Message Buffer */
    /* get the data */
    rx_data = LINFLEX_1.BDRM.R; // read whole register due to erratum e4897PS
    *pBuf = (uint8_t)rx_data; // take
    /* clear the DRF and RMB flags by writing 1 to them */
    LINFLEX_1.UARTSR.R = 0x0204;
}

 

Within the main I'm sending so characters first and then I'm trying to receive something. What I noticed is that after transmission the UARTSR[SZR] is set.

 

Thanks in advance,

Efim

Outcomes