반응형

//BLE USART


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
  ******************************************************************************
  * @file    main.c
  * @author  Ac6
  * @version V1.0
  * @date    01-December-2013
  * @brief   Default main function.
  ******************************************************************************
*/
 
#include "stm32f4xx.h"
/* Include my libraries here */
//#include "defines.h"
#include "tm_stm32f4_usart.h"
 
int main(void) {
    uint8_t c;
 
    TM_USART_Init(USART2, TM_USART_PinsPack_1, 9600);
    
    TM_USART_Puts(USART2, "Hello world\n");
    
    while (1) {
 
        /* Get character from internal buffer */
        c = TM_USART_Getc(USART2);
        if (c) {
            /* If anything received, put it back to terminal */
            TM_USART_Putc(USART2, c);
        }
    }
}
 
cs


// BLE USART Scanf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
  ******************************************************************************
  * @file    main.c
  * @author  Ac6
  * @version V1.0
  * @date    01-December-2013
  * @brief   Default main function.
  ******************************************************************************
*/
 
#include "stm32f4xx.h"
/* Include my libraries here */
//#include "defines.h"
#include "tm_stm32f4_usart.h"
 
char inputbuf[255];
int bufsize = 0;
 
char* ReadUartStr()
{
    int c;
    do {
        c = TM_USART_Getc(USART2);
        if (c) {
            if (c=='\n')
            {
                inputbuf[bufsize] = 0;
                bufsize=0;
                return inputbuf;
            }
            inputbuf[bufsize++= c;
        }
    } while (c);
    return 0;
}
 
int main(void) {
    uint8_t c;
 
    TM_USART_Init(USART2, TM_USART_PinsPack_1, 9600);
    TM_USART_Puts(USART2, "Hello world\n");
 
    int input;
    while (1) {
        char* str = ReadUartStr();
        if(str)
        {
            sscanf(str, "%d"&input);
            if (input == 1)
            {
                TM_USART_Puts(USART2, "hi");
            }
            if (input == 2)
            {
                TM_USART_Puts(USART2, "low");
            }
 
            //TM_USART_Puts(USART2, str);
        }
    }
}
 
 
 
 
cs


반응형

'Study > 32-bit MCUs' 카테고리의 다른 글

[Elevator(ARM)] Flash memory  (0) 2018.10.26
[Elevator(ARM)] ADC  (0) 2018.10.25
[Elevator(ARM)] key Matrix  (0) 2018.10.25
[Elevator(ARM)] DoorLock  (0) 2018.10.25
[Elevator(ARM)] Calculator  (0) 2018.10.25

+ Recent posts