AnsweredAssumed Answered

STM32F0 and HC 06

Question asked by jobert.edouard on Sep 1, 2015
Latest reply on Sep 1, 2015 by Clive One
Hello,
I am trying to send data to a computer with an HC 06 linked to an STM32F0 Discovery.

Here is my code :

                                                                                                                                       
 /* USART2 PA.2 Tx, PA.3 Rx STM32F0-Discovery*/
           
           
            /* Includes ------------------------------------------------------------------*/
            #include "main.h"
            #include "stdio.h"
             
            /* Private variables ---------------------------------------------------------*/
             
             
            /* Functions prototypes ---------------------------------------------------------*/
            void RCC_Configuration(void)
            { 
              RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /*Activation des clocks de l'usart2 et du port A*/
              RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
            }
             
           
           
            void configUSART2 (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(USART2, &USART_InitStructure);
                 USART_Cmd(USART2,ENABLE);
            }
           
           
            void configGPIOA (void)
            {
                 GPIO_InitTypeDef GPIO_InitStructure;
                 GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2 | GPIO_Pin_3;
              GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
              GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
              GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
              GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
              GPIO_Init(GPIOA, &GPIO_InitStructure);
                 GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
              GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
            }
           
           
            void Usart2Send(uint8_t data)
            {
                  USART_SendData(USART2, (uint8_t) data);
                  //Loop until the end of transmission
                  while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)// Wait for Empty
                  {
                  }
            }
           
           
            void outstring(char *s)
            {
              while(*s)
              {
                /* Loop until transmit data register is empty */
                while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)// Wait for Empty
             
                USART_SendData(USART2, (uint8_t)*s++);
              }
            }
           
           
           
           
            uint8_t Usart2Read(void){
                 
                 while ( USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
                 return (uint8_t)USART_ReceiveData(USART2);
            }
           
           
            int main(void)
            {
           
           
                 RCC_Configuration();
                 configUSART2();
                 configGPIOA();
                      
           
           
                 Usart2Send('A');
                 Usart2Send('T');
           
           
              while(1)
              { 
              }
            }
           

           
   

           
   

Here is what i get on Putty :
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒AT▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒n▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒Ǡ▒̸▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒l▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒A

I configured on keil on putty the same parameters : 9600baud, 8 bits data, 1 bit stop, no parity and no verification.
Any idea ? (by the way, I did not find how to put my code properly on the forum, sorry about that).

Thanks in advance

Outcomes