1 | #include "main.h"
|
2 |
|
3 |
|
4 | int main(void)
|
5 | {
|
6 | Init();
|
7 |
|
8 | while(1)
|
9 | {
|
10 | USART_SendData(USART1, 0xFF);
|
11 | while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
|
12 | }
|
13 | }
|
14 |
|
15 |
|
16 | /*******************************************************************************
|
17 | * Function Name : Init
|
18 | * Description : Initializes USART, GPIOS, Clocks
|
19 | * Input : None
|
20 | * Output : None
|
21 | * Return : None
|
22 | *******************************************************************************/
|
23 |
|
24 | void Init(void)
|
25 | {
|
26 |
|
27 |
|
28 | RCC_HSEConfig(RCC_HSE_OFF); // We are using the Internal clock source
|
29 |
|
30 | /* Initialize Reset Clock Control */
|
31 |
|
32 | RCC_ClocksTypeDef RCC_Clocks;
|
33 | RCC_GetClocksFreq(&RCC_Clocks);
|
34 | SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
|
35 |
|
36 |
|
37 | RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); // Specify we are using the // internal clock source
|
38 |
|
39 | RCC_USARTCLKConfig(RCC_USART1CLK_HSI); // I wrote this instruction to // ensure I am using USART1 with HSI, the apllication wasn't working before neither
|
40 |
|
41 | /* Enable GPIO clock */
|
42 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
43 |
|
44 | /* Enable USART1 Clock */
|
45 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
46 |
|
47 |
|
48 | GPIO_Config();
|
49 |
|
50 |
|
51 | USART_InitTypeDef USART_InitStructure;
|
52 |
|
53 | /* USART Initialisation for MIDI standard */
|
54 | USART_InitStructure.USART_BaudRate = 31250;
|
55 | USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
56 | USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
57 | USART_InitStructure.USART_Parity = USART_Parity_No;
|
58 | USART_InitStructure.USART_Mode = USART_Mode_Tx;
|
59 | USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
60 |
|
61 | USART_Init(USART1, &USART_InitStructure);
|
62 |
|
63 | USART_Cmd(USART1, ENABLE);
|
64 | }
|
65 |
|
66 | /**
|
67 | * @brief Configures GPIOS
|
68 | * @param None
|
69 | * @retval None
|
70 | */
|
71 | void GPIO_Config(void)
|
72 | {
|
73 |
|
74 | GPIO_InitTypeDef GPIO_InitStructure;
|
75 |
|
76 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
77 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
78 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
79 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
80 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
81 |
|
82 | GPIO_PinAFConfig(GPIOA, GPIO_Pin_2, GPIO_AF_0);
|
83 |
|
84 | }
|