2018-06-16 07:35 AM
I've been trying to connect USART_1 with bluetooth hc-05 for the past few days, andI am unable to do so. The Microcontroller I am using is nucleo STM32F103RB.
Here's the code (I am not using any library)
#define APB2_FREQ 72000000
void USART1_Send(char* data) { unsigned int length = 0; while(data[length] != '\0') ++length; int i = 0; while(i < length) { USART1_DR = data[i]; while((USART1_SR & 0x00000080) == 0); // wait if transmit data register is not empty ++i; } } char USART1_Receive() { while((USART1_SR & 0x00000020) == 0); //wait for data to arrive return USART1_DR; } void USART1_Init(int baudrate, short parity, short stop) { RCC_APB2ENR |= 0x00004004; // enable Port A, enable usart1 clock GPIOA_CRH &= 0xFFFFF00F; GPIOA_CRH |= 0x000004A0; // pin 9 = alternate function push-pull, pin 10 = Floating Input USART1_CR1 &= 0x00000000; // clear CR1 register and 'M bit' to 0(which is 8 bit data) if(parity == 1) // even parity USART1_CR1 |= 0x00000400; else if(parity == 2) USART1_CR1 |= 0x00000600; // odd parity USART1_CR2 &= 0x00000000; // Reset USART_CR2, 1 stop bit if(stop == 2) USART1_CR2 |= 0x00002000; // 2 stop bit USART1_BRR = APB2_FREQ /(baudrate); USART1_CR1 |= 0x00002000; // enable UART USART1_CR1 |= 0x0000000C; // enable Transmiter, receiver USART1_Send('LINK OK:\r\n'); } int main(void) { USART1_Init(9600, 0, 1); // 9600 baudrate, no parity, 1 stop bit while(1){ USART1_Send('Hello World\n'); } return (1); }This
program, configures USART1 and transmits Hello World. When I run the code in Keil uvision4, uart1 window prints Hello World repeatedly.
https://i.stack.imgur.com/oMl4o.png
However when I burn the code in STM32F103RB, and connect it with Bluetooth and pair the bluetooth with my mobile, it doesn't display anything on Bluetooth Terminal app in Mobile.
Here's how I've hooked up the wires,
I've tried the same Bluetooth with arduino and it worked fine.
Thanks!!!
#uart #stm32f103rb #bluetooth #keil-uvision Note: this post was migrated and contained many threaded conversations, some content may be missing.Solved! Go to Solution.
2018-06-17 04:17 AM
Can we use PLL to run HSI at 72MHZ in stm32f103rb?