AnsweredAssumed Answered

Nucleo-F103RB and USART2

Question asked by lemos.hugo on Jul 2, 2014
Hello

I was buy recently a Nucleo-F103RB
I downloaded  the libraries from ST stsw-stm32143

I am trying  modify the code of  "IO_Toggle" for send data to the PC thougt USART 2 and the USB connexion.

But I don't know because don't arrive nothing to PC. I put a Oscilloscope in TX PIN and there are no data in this pin.
I was looking for examples code and every body make code similar to me. Can someone help me? Thanks

I show you  the main.c code

/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
#define REGION
 
 
/** @addtogroup IO_Toggle
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static __IO uint32_t TimingDelay;
uint8_t __IO BlinkSpeed = 0;
/* Private function prototypes -----------------------------------------------*/
RCC_ClocksTypeDef RCC_Clocks;
/* Private functions ---------------------------------------------------------*/
 
int main(void)
{
   
  /** USART2 GPIO Configuration 
  PA2   ------> USART2_TX
  PA3   ------> USART2_RX
  */
  /****************************************************************************/
  GPIO_InitTypeDef GPIO_InitStruct;
   
  USART_InitTypeDef USART2_InitStruct;
   
  /****************************************************************************/
  /*Enable or disable APB2 peripheral clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
 
  /*Configure GPIO pin : PA */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PA */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOA, &GPIO_InitStruct);
   
  /****************************************************************************/
  /* USART_InitStruct members default value */
  USART2_InitStruct.USART_BaudRate = 9600;
  USART2_InitStruct.USART_WordLength = USART_WordLength_8b;
  USART2_InitStruct.USART_StopBits = USART_StopBits_1;
  USART2_InitStruct.USART_Parity = USART_Parity_No ;
  USART2_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  USART2_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 
     
  USART_DeInit(USART2);
  USART_Init(USART2, &USART2_InitStruct);
  //USART_StructInit(USART2_InitStruct);  
       
  //USART_ClockInitTypeDef *USART2_ClockInitStruct;
  //USART_ClockStructInit (USART2_ClockInitStruct);
     
  //USART_Init(USART2, USART2_InitStruct); 
  //USART_ClockInit(USART2, USART2_ClockInitStruct);
 
   
  USART_Cmd(USART2, ENABLE);
   
 
  /****************************************************************************/
   
     
 
   
   
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */ 
   
  /* SysTick end of count event each 1ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
   
  /* Initialize LED2 */
  STM_EVAL_LEDInit(LED2);
   
  /* Initialize User_Button on STM32NUCLEO */
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);  
   
  /* Initiate Blink Speed variable */
  BlinkSpeed = 0;
   
  /****************************************************************************/
   
   
  /* Infinite loop */
  while (1)
  {
 
    /* Test on blink speed */
    if(BlinkSpeed == 0)
    {
      /*LED2 Toggle each 50ms*/
      STM_EVAL_LEDToggle(LED2);
      Delay(50);     
    }     
    else if(BlinkSpeed == 1)
    {
      STM_EVAL_LEDToggle(LED2);
      /*LED2 Toggle each 200ms */
      Delay(200);
    }
   
     
    USART_SendData(USART2,0xAA55);
     
  }
}
 
/**
* @brief  Inserts a delay time.
* @param  nTime: specifies the delay time length, in 1 ms.
* @retval None
*/
void Delay(__IO uint32_t nTime)
{
  TimingDelay = nTime;
   
  while(TimingDelay != 0);
}
 
/**
* @brief  Decrements the TimingDelay variable.
* @param  None
* @retval None
*/
void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }
}
 
#ifdef  USE_FULL_ASSERT
 
/**
* @brief  Reports the name of the source file and the source line number
*         where the assert_param error has occurred.
* @param  file: pointer to the source file name
* @param  line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
  ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
   
  /* Infinite loop */
  while (1)
  {
  }
}
#endif












Regards

Outcomes