質問編集履歴
5
test
CHANGED
File without changes
|
test
CHANGED
@@ -358,4 +358,4 @@
|
|
358
358
|
|
359
359
|
### 追記
|
360
360
|
|
361
|
-
全ての組み合わせを確認できたわけではありませんが、
|
361
|
+
全ての組み合わせを確認できたわけではありませんが、メッセージの6(0開始)番目が0以外だと必ず発生しました。
|
4
test
CHANGED
File without changes
|
test
CHANGED
@@ -353,3 +353,9 @@
|
|
353
353
|
### 試したこと
|
354
354
|
|
355
355
|
ボーレートを115200や9600を試してもダメでした。
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
### 追記
|
360
|
+
|
361
|
+
全ての組み合わせを確認できたわけではありませんが、データ設定のメッセージの6(0開始)番目が0以外だと必ず発生しました。
|
3
test
CHANGED
File without changes
|
test
CHANGED
@@ -312,12 +312,20 @@
|
|
312
312
|
|
313
313
|
0x53, 0x34, 0xB8, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
314
314
|
|
315
|
+
|
316
|
+
|
315
317
|
0x53, 0x34, 0xB8, 0x64, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
316
318
|
|
319
|
+
|
320
|
+
|
317
321
|
0x53, 0x34, 0xB8, 0x64, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
318
322
|
|
323
|
+
|
324
|
+
|
319
325
|
0x53, 0x34, 0xB8, 0x64, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00
|
320
326
|
|
327
|
+
|
328
|
+
|
321
329
|
0x53, 0x34, 0xB8, 0x64, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00
|
322
330
|
|
323
331
|
|
@@ -326,6 +334,8 @@
|
|
326
334
|
|
327
335
|
0x53, 0x34, 0xB8, 0x64, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
328
336
|
|
337
|
+
|
338
|
+
|
329
339
|
0x53, 0x34, 0xB8, 0x64, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
330
340
|
|
331
341
|
|
2
修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
シリアルデータが受信できない時があります
|
1
|
+
Arduinoでシリアルデータが受信できない時があります
|
test
CHANGED
@@ -26,284 +26,280 @@
|
|
26
26
|
|
27
27
|
const int Spin = 8;
|
28
28
|
|
29
|
-
const int Upin = 9;
|
29
|
+
const int Upin = 9;
|
30
|
+
|
31
|
+
|
32
|
+
|
30
|
-
|
33
|
+
void setup()
|
34
|
+
|
35
|
+
{
|
36
|
+
|
37
|
+
Serial.begin(9600);
|
38
|
+
|
39
|
+
pinMode(Cpin, OUTPUT);
|
40
|
+
|
41
|
+
pinMode(Spin, OUTPUT);
|
42
|
+
|
43
|
+
pinMode(Upin, OUTPUT);
|
44
|
+
|
45
|
+
digitalWrite(Cpin, HIGH);
|
46
|
+
|
47
|
+
digitalWrite(Spin, HIGH);
|
48
|
+
|
49
|
+
digitalWrite(Upin, HIGH);
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
void loop()
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
SerialRead();
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
bool SerialRead()
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
int recv = 0;
|
70
|
+
|
71
|
+
bool result = false;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
//シリアル受信判定
|
76
|
+
|
77
|
+
if(Serial.available() > 0)
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
recv = Serial.read(); //1byteずつ吐き出し
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
//ヘッダー分岐
|
86
|
+
|
87
|
+
switch(recv)
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
case 'C' :
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
Hedder_C();
|
96
|
+
|
97
|
+
digitalWrite(Cpin, LOW);
|
98
|
+
|
99
|
+
setupData();
|
100
|
+
|
101
|
+
digitalWrite(Spin, LOW);
|
102
|
+
|
103
|
+
result = true;
|
104
|
+
|
31
|
-
|
105
|
+
break;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
case 'U' :
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
Hedder_U();
|
114
|
+
|
115
|
+
digitalWrite(Upin, LOW);
|
116
|
+
|
117
|
+
result = true;
|
118
|
+
|
119
|
+
break;
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
default:
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
break;
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
return result;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
void Hedder_C()
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
int recv = 0;
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
//データ数取得
|
152
|
+
|
153
|
+
while(1)
|
154
|
+
|
155
|
+
{
|
156
|
+
|
157
|
+
recv = Serial.read(); //1byteずつ吐き出し
|
158
|
+
|
159
|
+
if(recv != -1)
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
rxCount = recv;
|
164
|
+
|
165
|
+
rxCount++;
|
166
|
+
|
167
|
+
break;
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
void setupData()
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
int recv = 0;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
for(int k = 0; k < rxCount; k++)
|
186
|
+
|
187
|
+
{
|
188
|
+
|
189
|
+
//ヘッダー取得
|
190
|
+
|
191
|
+
while(1)
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
recv = Serial.read(); //1byteずつ吐き出し
|
196
|
+
|
197
|
+
if(recv == 'S')
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
//データ本体取得
|
202
|
+
|
203
|
+
for(int j = 0; j < DataMax; j++)
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
while(1)
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
recv = Serial.read(); //1byteずつ吐き出し
|
212
|
+
|
213
|
+
if(recv != -1)
|
214
|
+
|
215
|
+
{
|
216
|
+
|
217
|
+
rxData[k][j] = (byte)recv;
|
218
|
+
|
219
|
+
break;
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
break;
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
void Hedder_U()
|
240
|
+
|
241
|
+
{
|
242
|
+
|
243
|
+
int recv = 0;
|
244
|
+
|
245
|
+
int pos = 0;
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
//データ位置取得
|
250
|
+
|
251
|
+
while(1)
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
recv = Serial.read(); //1byteずつ吐き出し
|
256
|
+
|
257
|
+
if(recv != -1)
|
258
|
+
|
259
|
+
{
|
260
|
+
|
261
|
+
pos = recv;
|
262
|
+
|
263
|
+
break;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
//データ本体取得
|
272
|
+
|
273
|
+
for(int j = 0; j < DataMax; j++)
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
while(1)
|
278
|
+
|
279
|
+
{
|
280
|
+
|
281
|
+
recv = Serial.read(); //1byteずつ吐き出し
|
282
|
+
|
283
|
+
if(recv != -1)
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
rxData[pos][j] = (byte)recv;
|
288
|
+
|
289
|
+
break;
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
}
|
32
298
|
|
33
299
|
```
|
34
300
|
|
35
301
|
|
36
302
|
|
37
|
-
void setup()
|
38
|
-
|
39
|
-
{
|
40
|
-
|
41
|
-
Serial.begin(9600);
|
42
|
-
|
43
|
-
pinMode(Cpin, OUTPUT);
|
44
|
-
|
45
|
-
pinMode(Spin, OUTPUT);
|
46
|
-
|
47
|
-
pinMode(Upin, OUTPUT);
|
48
|
-
|
49
|
-
digitalWrite(Cpin, HIGH);
|
50
|
-
|
51
|
-
digitalWrite(Spin, HIGH);
|
52
|
-
|
53
|
-
digitalWrite(Upin, HIGH);
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
void loop()
|
60
|
-
|
61
|
-
{
|
62
|
-
|
63
|
-
SerialRead();
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
bool SerialRead()
|
70
|
-
|
71
|
-
{
|
72
|
-
|
73
|
-
int recv = 0;
|
74
|
-
|
75
|
-
bool result = false;
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
//シリアル受信判定
|
80
|
-
|
81
|
-
if(Serial.available() > 0)
|
82
|
-
|
83
|
-
{
|
84
|
-
|
85
|
-
recv = Serial.read(); //1byteずつ吐き出し
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
//ヘッダー分岐
|
90
|
-
|
91
|
-
switch(recv)
|
92
|
-
|
93
|
-
{
|
94
|
-
|
95
|
-
case 'C' :
|
96
|
-
|
97
|
-
{
|
98
|
-
|
99
|
-
Hedder_C();
|
100
|
-
|
101
|
-
digitalWrite(Cpin, LOW);
|
102
|
-
|
103
|
-
setupData();
|
104
|
-
|
105
|
-
digitalWrite(Spin, LOW);
|
106
|
-
|
107
|
-
result = true;
|
108
|
-
|
109
|
-
break;
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
case 'U' :
|
114
|
-
|
115
|
-
{
|
116
|
-
|
117
|
-
Hedder_U();
|
118
|
-
|
119
|
-
digitalWrite(Upin, LOW);
|
120
|
-
|
121
|
-
result = true;
|
122
|
-
|
123
|
-
break;
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
default:
|
128
|
-
|
129
|
-
{
|
130
|
-
|
131
|
-
break;
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
return result;
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
void Hedder_C()
|
148
|
-
|
149
|
-
{
|
150
|
-
|
151
|
-
int recv = 0;
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
//データ数取得
|
156
|
-
|
157
|
-
while(1)
|
158
|
-
|
159
|
-
{
|
160
|
-
|
161
|
-
recv = Serial.read(); //1byteずつ吐き出し
|
162
|
-
|
163
|
-
if(recv != -1)
|
164
|
-
|
165
|
-
{
|
166
|
-
|
167
|
-
rxCount = recv;
|
168
|
-
|
169
|
-
rxCount++;
|
170
|
-
|
171
|
-
break;
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
void setupData()
|
182
|
-
|
183
|
-
{
|
184
|
-
|
185
|
-
int recv = 0;
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
for(int k = 0; k < rxCount; k++)
|
190
|
-
|
191
|
-
{
|
192
|
-
|
193
|
-
//ヘッダー取得
|
194
|
-
|
195
|
-
while(1)
|
196
|
-
|
197
|
-
{
|
198
|
-
|
199
|
-
recv = Serial.read(); //1byteずつ吐き出し
|
200
|
-
|
201
|
-
if(recv == 'S')
|
202
|
-
|
203
|
-
{
|
204
|
-
|
205
|
-
//データ本体取得
|
206
|
-
|
207
|
-
for(int j = 0; j < DataMax; j++)
|
208
|
-
|
209
|
-
{
|
210
|
-
|
211
|
-
while(1)
|
212
|
-
|
213
|
-
{
|
214
|
-
|
215
|
-
recv = Serial.read(); //1byteずつ吐き出し
|
216
|
-
|
217
|
-
if(recv != -1)
|
218
|
-
|
219
|
-
{
|
220
|
-
|
221
|
-
rxData[k][j] = (byte)recv;
|
222
|
-
|
223
|
-
break;
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
break;
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
void Hedder_U()
|
244
|
-
|
245
|
-
{
|
246
|
-
|
247
|
-
int recv = 0;
|
248
|
-
|
249
|
-
int pos = 0;
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
//データ位置取得
|
254
|
-
|
255
|
-
while(1)
|
256
|
-
|
257
|
-
{
|
258
|
-
|
259
|
-
recv = Serial.read(); //1byteずつ吐き出し
|
260
|
-
|
261
|
-
if(recv != -1)
|
262
|
-
|
263
|
-
{
|
264
|
-
|
265
|
-
pos = recv;
|
266
|
-
|
267
|
-
break;
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
}
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
//データ本体取得
|
276
|
-
|
277
|
-
for(int j = 0; j < DataMax; j++)
|
278
|
-
|
279
|
-
{
|
280
|
-
|
281
|
-
while(1)
|
282
|
-
|
283
|
-
{
|
284
|
-
|
285
|
-
recv = Serial.read(); //1byteずつ吐き出し
|
286
|
-
|
287
|
-
if(recv != -1)
|
288
|
-
|
289
|
-
{
|
290
|
-
|
291
|
-
rxData[pos][j] = (byte)recv;
|
292
|
-
|
293
|
-
break;
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
```
|
304
|
-
|
305
|
-
|
306
|
-
|
307
303
|
### 受信するシリアルデータ
|
308
304
|
|
309
305
|
1. 総データ数:0x43(ヘッダーC), 0x00(データ数-1)
|
1
タグ追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,7 +26,11 @@
|
|
26
26
|
|
27
27
|
const int Spin = 8;
|
28
28
|
|
29
|
-
const int Upin = 9;
|
29
|
+
const int Upin = 9;```ここに言語を入力
|
30
|
+
|
31
|
+
コード
|
32
|
+
|
33
|
+
```
|
30
34
|
|
31
35
|
|
32
36
|
|