2016-09-10 11:33 AM
Hi!
I have problem with connection between my mobile phone and my Nucleo board by Bluetooth. How You see in subject I have a HC-06 and I can't connect with my mobile phone. When I try to do the same with my PC everything was good (I use USART2) and now isn't. I have not idea what's wrong. You see i try by USART1, USART2 without results.It is my code. If you have any suggestions I will be grateful&sharpinclude ''stm32f4xx.h''&sharpinclude <stdio.h>void delay(int czas){ int i=0; for(i=0; i<czas*2000; i++);}//Ustawienie dla diody LED na p?ytce Nucleovoid GPIOA_LED_init(void){ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitTypeDef gpio; gpio.GPIO_Pin = GPIO_Pin_5; gpio.GPIO_Mode = GPIO_Mode_OUT; gpio.GPIO_OType = GPIO_OType_PP; gpio.GPIO_PuPd = GPIO_PuPd_NOPULL; gpio.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOA, &gpio);}//Ustawienie USART1void USART2_init(void){ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB, ENABLE); GPIO_InitTypeDef gpio; //PIN2 to TX gpio.GPIO_Pin = GPIO_Pin_6; gpio.GPIO_Mode = GPIO_Mode_AF; gpio.GPIO_OType = GPIO_OType_PP; gpio.GPIO_PuPd = GPIO_PuPd_NOPULL; //gpio.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOB, &gpio); GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); //PIN3 to RX gpio.GPIO_Pin = GPIO_Pin_10; gpio.GPIO_Mode = GPIO_Mode_AF; gpio.GPIO_OType = GPIO_OType_OD; gpio.GPIO_PuPd = GPIO_PuPd_UP; // gpio.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOA, &gpio); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); USART_InitTypeDef usart; //Konfiguracja usarta usart.USART_BaudRate = 9600; usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None; usart.USART_Mode = USART_Mode_Rx|USART_Mode_Tx; usart.USART_Parity = USART_Parity_No; usart.USART_StopBits = USART_StopBits_1; usart.USART_WordLength = USART_WordLength_8b; USART_Init(USART1, &usart); USART_Cmd(USART1, ENABLE);}//Wysy?anie znaku przez UART2void USART2_send_char( uint8_t znak){ while( USART_GetFlagStatus(USART1, USART_FLAG_TXE)==RESET ); //jesli bufor pusty USART_SendData(USART1, znak);}int __io_putchar(int c){ USART2_send_char(c); return c;}int main(void){ GPIOA_LED_init(); // GPIOC_BUTTON_init(); USART2_init(); for(;;) { if (USART_GetFlagStatus(USART1, USART_FLAG_RXNE)) { char c = USART_ReceiveData(USART2); switch (c) { case 'a': GPIO_SetBits(GPIOA, GPIO_Pin_5); // zapalenie diody printf(''connection''); // delay(100); break; case 'b': GPIO_ResetBits(GPIOA, GPIO_Pin_5); // zgaszenie diody // delay(400); break; default: //GPIO_SetBits(GPIOA, GPIO_Pin_5); break; } } }//for}//main #eclipse #nucleo #stm32