Question
STM32F407 Discovery + HC-05 bluetooth + PC putty
Posted on August 11, 2014 at 15:16
Hello,
i am new to forum, and also to stm32 discovery. So please some patience :).I am trying to send from discovery to PC.Tried with USART6 + UART2USB and in putty on PC everything works.Then i connected HC-05 to same USART6, just set baudrate to 38400 and tried again.Everytime i reset whole system (connecting BT, running code) in manage to get 2 character aA but then just ▒ signs. I do not understand, what i missed. My code in bellow. I tried to lower to 9600 without success.Any idea or advice for lost begginer?thank you for help, with regardsRobertmy code:/* Includes ------------------------------------------------------------------*/#include ''main.h''#include ''stm32f4xx.h''#include ''stm32f4_discovery.h''/* Private variables ---------------------------------------------------------*/static __IO uint32_t uwTimingDelay;RCC_ClocksTypeDef RCC_Clocks;/* Private function prototypes -----------------------------------------------*/static void Delay(__IO uint32_t nTime);void RCC_Configuration(void) { /* ENABLE CLOCKS */ /* GPIOC clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* USART6 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);}void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructureUSART; GPIO_InitStructureUSART.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructureUSART.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructureUSART.GPIO_OType = GPIO_OType_PP; GPIO_InitStructureUSART.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructureUSART.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructureUSART); GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);}void USART_Configuration(void) { USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 38400; 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(USART6, &USART_InitStructure); USART_Cmd(USART6, ENABLE); }int main(void){ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); uint8_t Data; RCC_Configuration(); GPIO_Configuration(); USART_Configuration(); while (1) { //a Data = 0x61; while(USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART6, (uint8_t) Data); // Echo Char //A Data = 0x41; while(USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART6, (uint8_t) Data); // Echo Char Data = 0; /* Insert 50 ms delay */ Delay(20); /* Infinite loop */ }}void Delay(__IO uint32_t nTime){ uwTimingDelay = nTime; while(uwTimingDelay != 0);}/** * @brief Decrements the TimingDelay variable. * @param None * @retval None */void TimingDelay_Decrement(void){ if (uwTimingDelay != 0x00) { uwTimingDelay--; }}
