File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed
03_Serial_UART1/Serial_UART1 Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change 1
- /*
2
- Serial for UART2
1
+ /*
2
+ Serial for UART1
3
3
我们使用“ HardwareSerial ”类进行串行通信。它有一些重要的接口:
4
4
- HardwareSerial(int uart_nr):这是HardwareSerial的构造函数,其中uart_nr为0,1或2,所以我们有最多3个串行端口。
5
5
16
16
http://
17
17
*/
18
18
19
- HardwareSerial Serial2 ( 2 );
19
+ HardwareSerial Serial1 ( 1 );
20
20
21
- int8_t U2rxPin = 16 ;
22
- int8_t U2txPin = 17 ;
21
+ int8_t U1rxPin = 16 ;
22
+ int8_t U1txPin = 17 ;
23
23
24
24
char inByte = 0 ; // incoming serial byte
25
25
// the setup routine runs once when you press reset:
26
26
void setup ()
27
27
{
28
28
// initialize serial communication at 115200 bits per second:
29
- Serial2 .begin (115200 ,SERIAL_8N1,U2rxPin,U2txPin );
30
- while (!Serial2 )
29
+ Serial1 .begin (115200 ,SERIAL_8N1,U1rxPin,U1txPin );
30
+ while (!Serial1 )
31
31
{
32
32
; // wait for serial port to connect. Needed for native USB port only
33
33
}
34
34
// serial print hello world.
35
- Serial2 .println (" Hello world!" );
35
+ Serial1 .println (" Hello world!" );
36
36
}
37
37
38
38
// the loop routine runs over and over again forever:
39
39
void loop ()
40
40
{
41
41
// print out the value if Serial available.
42
- if (Serial2 .available () > 0 )
42
+ if (Serial1 .available () > 0 )
43
43
{
44
44
// get incoming byte:
45
- inByte = Serial2 .read ();
45
+ inByte = Serial1 .read ();
46
46
// send back values:
47
- Serial2 .write (inByte);
47
+ Serial1 .write (inByte);
48
48
}
49
49
}
You can’t perform that action at this time.
0 commit comments