Skip to main content
Pooja WANI
Associate III
August 12, 2019
Solved

While programming for UART in receiver mode, SZF bit in UARTSR gets set and LINFLEX enters the sleep mode. Why is this so?

  • August 12, 2019
  • 3 replies
  • 1281 views

..

    This topic has been closed for replies.
    Best answer by Erwan YVIN

    Hello ,

    In which state are you ?

    Stuck at Zero Flag

    This bit is set by hardware when the bus is dominant for more than a 100-bit time. If the dominant

    state continues, SZF flag is set again after 87-bit time. It is cleared by software.

    Are you sure that you have plugged correctly the Error Interruption callback ?

    Best regards

    Erwan

    3 replies

    Erwan YVIN
    Erwan YVINBest answer
    ST Employee
    August 13, 2019

    Hello ,

    In which state are you ?

    Stuck at Zero Flag

    This bit is set by hardware when the bus is dominant for more than a 100-bit time. If the dominant

    state continues, SZF flag is set again after 87-bit time. It is cleared by software.

    Are you sure that you have plugged correctly the Error Interruption callback ?

    Best regards

    Erwan

    Pooja WANI
    Associate III
    August 21, 2019

    Hello,

    I could perform UART reception successfully.

    However, I was using pins PB[0] and PB[1] earlier for Transmission and Reception. UART transmitter was working properly using these pins and there was problem while reception. Same code when used with pins PB[2] and PB[3], Transmission and Reception both are working successfully.

    Can you please tell me what can be the problem over here?

    Thanks and Regards,

    Pooja WANI

    Pooja WANI
    Associate III
    August 13, 2019

    Hello,

    I have copied the code below.

    #include "components.h"

    void UART_Init(void);

    void GPIO_Init(void);

    void UART_Transmit(uint8_t);

    void UART_Receive(void);

    uint8_t TransData[] = {"Hello World...!\n\r"};

    #define NUMBER_OF_BYTES_SENT sizeof(TransData)

    uint8_t ReceivedData;

    /*

     * Application entry point.

     */

    int main(void)

    {

     unsigned short j = 0;

     /* Initialization of all the imported components in the order specified in

       the application wizard. The function is generated automatically.*/

     componentsInit();

     GPIO_Init();

     UART_Init();

     /* Transmit welcome message */

     for (j = 0; j < NUMBER_OF_BYTES_SENT; j++) /* Loop for character string */

     {

     UART_Transmit(TransData[j]);

     }

     /* Application main loop.*/

     while(1)

     {

     UART_Receive();

     UART_Transmit(ReceivedData);

     }

    }

    void UART_Transmit(uint8_t ch)

    {

    unsigned char *ptr = (unsigned char *)&LINFLEX_0.BDRL.R + 3;

    *ptr = ch; /* write character to transmit buffer */

    while (1 != LINFLEX_0.UARTSR.B.DTF); /* Wait for data transmission completed flag */

    LINFLEX_0.UARTSR.R = 0x0002;

    }

    void UART_Receive(void)

    {

    while (LINFLEX_0.UARTSR.B.DRF != 1);

    while (LINFLEX_0.UARTSR.B.RMB != 1);

    ReceivedData = (uint8_t) LINFLEX_0.BDRM.B.DATA4;

    LINFLEX_0.UARTSR.R = 0x0204;    /* clear the DRF and RMB flags */

    }

    void UART_Init(void)

    {

    /*Alternate functions are chosen by setting the values of the PCR.PA bit-fields inside the SIUL module.

    PCR.PA = 00 for AF0; PCR.PA = 01 for AF1; PCR.PA = 10 for AF2; PCR.PA = 11 for AF2.

    This is intended to select the output functions;

    to use one of the input functions, the PCR.IBE bit must be written to ‘1’, regardless of the values selected in the PCR.PA bit-fields. */

    /* UART Tx and Rx */

    SIU.PCR[16].R = 0x0E00;

    SIU.PCR[17].R = 0x0100;

    /* LINFLEX in an Initialization mode */

    LINFLEX_0.LINCR1.B.INIT = 1;

    LINFLEX_0.LINCR1.B.SLEEP = 0;

    /* wait for the INIT mode */

    //while (0x1000 != (LINFLEX_0.LINSR.R && 0xF000));

    LINFLEX_0.LINSR.R = 0xFFFF; /* Clearing LINSR register */

    LINFLEX_0.UARTSR.R = 0xFFFF; /* Clearing UARTSR register */

    /* Start UART mode */

    LINFLEX_0.UARTCR.B.UART = 1;

    LINFLEX_0.UARTCR.R = 0x0003; /* 8-bit data, Parity transmit/check disabled */

    /* Generate Baud Rate = 115200 at 16 MHz */

    /* BAUD RATE = 16 MHz/(16 * LFDIV)

    For Baud Rate of 115200, LFDIV = 8.68

    LINFBRR = 16 * 0.68 = 11d i.e. 0xB & LINIBRR = 0x8 */

    LINFLEX_0.LINFBRR.B.DIV_F = 0xB;  /* LINFBRR (containing the fraction bits must be programmed before the LINIBRR */

    LINFLEX_0.LINIBRR.B.DIV_M = 0x8;

    /* Exit Initialization mode */

    LINFLEX_0.LINCR1.B.INIT = 0;

    LINFLEX_0.LINCR1.B.SLEEP = 0;

    /* Transmit buffer size = 1 byte, Enable Transmission, Enable Reception */

    LINFLEX_0.UARTCR.B.TDFLTFC = 0;

    LINFLEX_0.UARTCR.B.TXEN = 1;

    LINFLEX_0.UARTCR.B.RXEN = 1;

    }

    Transmitter in this code is working . But, Receiver part is not working. TO flag in UARTSR register is getting set before receiving a single byte. Please, go throgh the code once if I am missing something in the code.

    Thanks and Regards,

    Pooja Wani

    Pooja WANI
    Associate III
    August 13, 2019

    while (LINFLEX_0.UARTSR.B.DRF != 1);

    It is getting stuck over here. DRF flag does not get set.