cancel
Showing results for 
Search instead for 
Did you mean: 

Why is my uart rx not working?

DBles.1
Associate II

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?

11 REPLIES 11

How do you recommend receiving without an ISR?

UART1_ReceiveData8