AnsweredAssumed Answered

First Printf, some problems :-(

Question asked by martinez.diego.002 on Apr 12, 2014
Latest reply on Apr 15, 2014 by Clive One
Hello,
I,m working with my first usart test, and along 3 hours I have worked a readed to many documentation but my printf doesn't work, could anyone help me? Thanks in advance.


//************INCLUDES*******************
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "_delays_diego.h"
#include "_Diego_Pwm.h"
#include "stm32f10x_usart.h"
#include <stdio.h>
//************FUNCIONES******************
void SetupClock(void);
void SetupGpio(void);
void SetupUsart1(void);
void Usart1Put(uint8_t ch);
uint8_t Usart1Get(void);
int main(void)
{
    SetupClock();
    SetupGpio();
    SetupUsart1();
    Delay_Setup(24);//setup a libreria delay

    while(1)
    {
            GPIOC->ODR|=(1<<8);
            _Delay_ms(500);
            Usart1Put('A');//work fine
            GPIOC->ODR|=(1<<9);
            _Delay_ms(500);
            GPIOC->ODR&=~(1<<8);
            _Delay_ms(500);
            GPIOC->ODR&=~(1<<9);
            _Delay_ms(500);
            printf("Hello World!\r\n");//**************DON'T WORK********************
    }
}
void Usart1Put(uint8_t ch)//escriben solo valor de 8 bits
{
      USART_SendData(USART1, (uint8_t) ch);
      //Loop until the end of transmission
      while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
      {
      }
}
uint8_t Usart1Get(void){
     while ( USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
        return (uint8_t)USART_ReceiveData(USART1);
}
void SetupClock(void)
{
          RCC_DeInit ();                    /* RCC system reset(for debug purpose)*/
          RCC_HSEConfig (RCC_HSE_ON);       /* Habilitamos oscilador externo, cuarzo 8 mhz  */
          /* Wait till HSE is ready                                                         */
          while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
          RCC_HCLKConfig   (RCC_SYSCLK_Div1);   /* HCLK   = SYSCLK                */
          RCC_PCLK2Config  (RCC_HCLK_Div1);     /* PCLK2  = HCLK = APB2CLOCK      */
          RCC_PCLK1Config  (RCC_HCLK_Div1);     /* PCLK1  = HCLK = APB1CLOCK      */
          /* PLLCLK = 8MHz * 3 = 24 MHz                                           */
          RCC_PLLConfig(0x00010000, RCC_PLLMul_3);/*PLL Source hse div1 y multi*3*/
          RCC_PLLCmd (ENABLE);                  /* Enable PLL                     */
          /* Wait till PLL is ready                                               */
          while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
          /* Select PLL as system clock source                                    */
          RCC_SYSCLKConfig (RCC_SYSCLKSource_PLLCLK);
          /* Wait till PLL is used as system clock source                         */
          while (RCC_GetSYSCLKSource() != 0x08);
          //******HABILITAMOS EL CLOCK A LOS PERIFERICOS QUE NECESITEMOS****************
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//damos clock a los puertos a usar
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);//damos clock a usart1 y a gpioa por donde usaremos usart1
}
void SetupGpio(void)
{
        GPIO_InitTypeDef GPIO_InitStruct;//GPIO_InitStruct es la variable que utilizaremos para acceder a los miembros de la estructura.
        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
        GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_Init(GPIOC,&GPIO_InitStruct);//pasamo los valores a la función GPIO_Init
          /* Configure USART1 Rx (PA10) as input floating                         */
        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
          /* Configure USART1 Tx (PA9) as alternate function push-pull            */
        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void SetupUsart1(void)
{
        USART_InitTypeDef USART_InitStructure;
        USART_InitStructure.USART_BaudRate            = 9600;
        USART_InitStructure.USART_WordLength          = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits            = USART_StopBits_1;
        USART_InitStructure.USART_Parity              = USART_Parity_No ;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
        USART_Init(USART1, &USART_InitStructure);
        USART_Cmd(USART1, ENABLE);
}





Outcomes