Skip to main content
Visitor II
April 25, 2023
Question

Why is my uart rx not working?

  • April 25, 2023
  • 8 replies
  • 3745 views

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.

    8 replies

    Graduate
    April 25, 2023

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

    DBles.1Author
    Visitor II
    April 25, 2023

    Hi, see initialization file attached.

    Graduate
    April 26, 2023

    Try UART1_Cmd(ENABLE);

    Graduate
    April 26, 2023

    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)

    DBles.1Author
    Visitor II
    April 26, 2023

    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.

    Graduate II
    April 28, 2023

    > 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.1Author
    Visitor II
    April 26, 2023

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

    Graduate
    April 27, 2023

    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

    Visitor II
    April 27, 2023

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

    DBles.1Author
    Visitor II
    May 1, 2023

    How do you recommend receiving without an ISR?

    Visitor II
    May 1, 2023

    UART1_ReceiveData8