@@ -19,43 +19,49 @@ using namespace machinecontrol;
19
19
20
20
unsigned long counter = 0 ;
21
21
22
- void setup () {
23
-
24
- Serial.begin (9600 );
25
- while (!Serial) {
26
- ; // wait for serial port to connect.
27
- }
28
- Serial.println (" Start RS485 initialization" );
29
-
30
- // Initialize the serial interface, enable the
31
- // RS485 on SP335ECR1 and set as full duplex
32
- comm_protocols.rs485 .begin (9600 );
33
- comm_protocols.rs485 .enable = 1 ;
34
- comm_protocols.rs485 .sel_485 = 1 ;
35
- comm_protocols.rs485 .half_duplex = 0 ;
36
-
37
- Serial.println (" Initialization done!" );
22
+ void setup ()
23
+ {
24
+
25
+ Serial.begin (115200 );
26
+ while (!Serial) {
27
+ ; // wait for serial port to connect.
28
+ }
29
+ delay (1000 );
30
+ Serial.println (" Start RS485 initialization" );
31
+
32
+ comm_protocols.rs485 .begin (115200 );
33
+ comm_protocols.rs485 .enable = 1 ; // SDHN_N
34
+ comm_protocols.rs485 .sel_485 = 1 ; // RS485_RS232_N
35
+ comm_protocols.rs485 .half_duplex = 0 ; // HALF_FULL_N
36
+ comm_protocols.rs485 .receive (); // RE_N
37
+ comm_protocols.rs485 .fd_tx_term = 1 ; // FD_TX_TERM - 120 Ohm Y-Z termination enabled when both TERM and FD_TX_TERM are high
38
+ comm_protocols.rs485 .term = 1 ; // TERM - 120 Ohm A-B termination enabled when high
39
+
40
+ Serial.println (" Initialization done!" );
38
41
}
39
42
43
+ constexpr unsigned long sendInterval { 1000 };
44
+ unsigned long sendNow { 0 };
45
+
46
+ constexpr unsigned long halfFullInterval { 5000 };
47
+ unsigned long halfFull { 0 };
48
+ byte halfFullStatus { 0 };
49
+
50
+ void loop ()
51
+ {
52
+ while (comm_protocols.rs485 .available ())
53
+ Serial.write (comm_protocols.rs485 .read ());
54
+
55
+ if (millis () > sendNow) {
56
+ comm_protocols.rs485 .noReceive ();
57
+ comm_protocols.rs485 .beginTransmission ();
58
+
59
+ comm_protocols.rs485 .print (" hello " );
60
+ comm_protocols.rs485 .println (counter++);
61
+
62
+ comm_protocols.rs485 .endTransmission ();
63
+ comm_protocols.rs485 .receive ();
40
64
41
- void loop () {
42
- // Call receive(); sets the flux control pins properly
43
- // and allows receiving data if available
44
- comm_protocols.rs485 .receive ();
45
- if (comm_protocols.rs485 .available ()) {
46
- Serial.print (" read byte: " );
47
- Serial.write (comm_protocols.rs485 .read ());
48
- Serial.println ();
49
- }
50
- // Call beginTransmission(); sets the flux control pins properly
51
- // and allows starting a trasnsmission.
52
- // If instead of a string, you want
53
- // to send bytes, use the API write();
54
- comm_protocols.rs485 .beginTransmission ();
55
- comm_protocols.rs485 .print (" hello " );
56
- comm_protocols.rs485 .println (counter);
57
- comm_protocols.rs485 .endTransmission ();
58
- counter++;
59
-
60
- delay (1000 );
65
+ sendNow = millis () + sendInterval;
66
+ }
61
67
}
0 commit comments