Skip to main content
DBles.1
Associate II
Apr 25, 2023 3:52 PM UTC
Question

Why is my uart rx not working?

Code shown in details. I am guessing something is wrong with clocks - this doesn't make sense though since tx is working just fine. I see signals just fine on the scope. Both tx and rx are high during no transmit. Clocks and initialization code shown below.

CLK_DeInit(); // set the CLK peripherals to reset value 

CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1); // set the master clock to HSI 16M

  CLK_SYSCLKConfig(CLK_SOURCE_HSI); 

CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV4); // set the cpu & window watch dog clock to 16M/4

CLK_CCOConfig(CLK_OUTPUT_CPUDIV4); // we are outputting the fCPU/4 (4MHz/4 = 1MHz) - PC4 CLK_CCO

TIM6_DeInit();             // TIM1 Peripheral Configuration Clear

TIM6_InternalClockConfig(); // select timer 6 to run from internal clock

TIM6_TimeBaseInit(TIM6_PRESCALER_64, 250 ); // set the timer clk and up count

TIM6_ITConfig(TIM6_IT_UPDATE, ENABLE); // turn on the interrup

/* Initialize PC5 I/Os in Output Mode for testing timer */

GPIO_Init(GPIOC, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_FAST); // turn on port 5 as fast push pull output

/* Enable TIM6 */

TIM6_Cmd(ENABLE);

TIM5_TimeBaseInit(TIM5_PRESCALER_1 , 400);     // Rev 1.01 Toro change to 1Khz PWM for voltage regulator issues due to PEM PWM

TIM5_OC1Init(TIM5_OCMODE_PWM2, TIM5_OUTPUTSTATE_ENABLE, 0, TIM5_OCPOLARITY_LOW); 

TIM5_Cmd(ENABLE); // turn on timer 5

  TIM1_DeInit();                    //TIM1 Peripheral Clear

  TIM1_TimeBaseInit(8, TIM1_COUNTERMODE_UP, clutch_up_count, 0);      //setup time base unit at 1kHz

  TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE,

        0, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET,

        TIM1_OCNIDLESTATE_RESET); //Inititilzie output channel 3 to use Timer 1 for Clutch_EN PWM

  TIM1_CtrlPWMOutputs(ENABLE); // enable PWM outputs on timer 1

  TIM1_Cmd(ENABLE);

uart init code below

  UART1_DeInit();

// UART pins

  GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_FAST);  // TX pin, PD5  

  GPIO_Init(GPIOD, GPIO_PIN_6, GPIO_MODE_IN_PU_NO_IT);    // RX pin, PD6 GPIO_MODE_IN_PU_NO_IT GPIO_MODE_IN_FL_IT

  CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE);  //Enable clock for UART

  UART1->CR1 = 0;

  UART1->CR2 = 0b00101100;    // enable TX RX, enable RX interrupt

  UART1->CR3 = 0;

  UART1->BRR2 = 0x0B;

  UART1->BRR1 = 0x08;

  //Note: Writing of BRR2 must precede BRR1 because writing of BRR1 will update the baud counter.

   

   

UART1_ReceiverWakeUpCmd(ENABLE);

interrupt code

 INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18)

{

}

This is also called in init

enableInterrupts();

Thoughts?

    This topic has been closed for replies.

    11 replies

    Senior III
    Apr 25, 2023 4:05 PM UTC

    Please paste whole file *.c. that's you paste is hard to read ​

    Dudo
    DBles.1
    DBles.1Author
    Associate II
    Apr 25, 2023 5:33 PM UTC

    Hi, see initialization file attached.

    Senior III
    Apr 26, 2023 8:20 AM UTC

    Try UART1_Cmd(ENABLE);

    Dudo
    Senior III
    Apr 26, 2023 8:35 AM UTC

    why don't you use function?

    void UART1_Init(uint32_t BaudRate, UART1_WordLength_TypeDef WordLength, 
     UART1_StopBits_TypeDef StopBits, UART1_Parity_TypeDef Parity, 
     UART1_SyncMode_TypeDef SyncMode, UART1_Mode_TypeDef Mode)

    Dudo
    DBles.1
    DBles.1Author
    Associate II
    Apr 26, 2023 5:16 PM UTC

    As you can see in the notes for the uart initi function:

    * Note:      - The longest string has 28 characters, and UART needs to send them in less than 1ms

    *         - Use 115200 Baud rate as a default

    *         - The UART1_Init() function of ST library is not working, so UART1 configuration is done by changing directly register values

    The not is that the uart1 init function is not working. I am guessing this has to do with clocks. But I cannot see how yet.

    Piranha
    Principal III
    Apr 28, 2023 2:04 AM UTC

    > The longest string has 28 characters, and UART needs to send them in less than 1ms

    > Use 115200 Baud rate as a default

    First, your requirements are non-sense...

    28 B/ms = 28'000 B/s = 280'000 b/s

    DBles.1
    DBles.1Author
    Associate II
    Apr 26, 2023 5:16 PM UTC

    I did try the UART1_Cmd enable function also - same results. No rx isr.

    Senior III
    Apr 27, 2023 7:13 AM UTC

    I have no idea. Perhaps better way is use example for UART1 form ST and make sure the HW is ok?

    https://www.st.com/en/embedded-software/stsw-stm8069.html

    Dudo
    AA1
    Senior III
    Apr 27, 2023 10:15 AM UTC

    Before try to receive with interrupt, try to receive without interrupt.

    DBles.1
    DBles.1Author
    Associate II
    May 1, 2023 10:46 PM UTC

    How do you recommend receiving without an ISR?

    YvanR
    Associate II
    May 1, 2023 11:24 PM UTC

    UART1_ReceiveData8