Ви не увійшли.
Сторінки 1
Похоже что линия i2c перестает работать с некоторой периодичностью на 0,1 сек.
Датчики какие? DS18B20 ? Если да, так измерение температуры занимает время.
Использую термистор. Функции delay() почти не использую, и в любом случае Slave работает по прерываниям, а Master тупо отрабатывает функци без прерываний.
Если ты хочешь, чтобы кто-то действительно попытался разобраться, выкладывай коды полностью - со всеми описаниями, инклудами и т.п. Без этого здесь будет только тыкание пальцем в небо и глум со срачем, ибо неxyй.
Спецом сделал очищенный скетч от всего. Все то же самое. Периодически на Slave приходит мусор. Я даже скорость до 10к уменьшил.
Master:
#include <Wire.h>
unsigned int Command = 0;
char TwoBytes [2];
bool SetTemperatureToController (double TemperatureToSet, byte ControllerToSet) {
//Отправить температуру
Command = TemperatureToSet * 10;
Wire.beginTransmission(ControllerToSet);
Wire.write(Command >> 8);
Wire.write(Command & 0xFF);
Wire.endTransmission();
Serial.print("Sended: ");Serial.print(Command);
//Команда на получение температуры
Command = 3;
Wire.beginTransmission(ControllerToSet);
Wire.write(Command >> 8);
Wire.write(Command & 0xFF);
Wire.endTransmission();
Serial.print(" && ");Serial.println(Command);
//Получить температуру
Wire.requestFrom((int)ControllerToSet, (int)2);
TwoBytes[0] = NULL;
TwoBytes[1] = NULL;
while (Wire.available()) {
TwoBytes[0] = Wire.read();
TwoBytes[1] = Wire.read();
while (Wire.available()) {
Wire.read();
}
}
Command = 0;
Command = ((unsigned int)TwoBytes[0] << 8) + ((unsigned int)TwoBytes[1]);
Serial.print("Receiv: ");Serial.print(Command);
//Serial.print(TemperatureToSet); Serial.print(" == "); Serial.println((double)Command/10);
//Проверка на успешное задание температуры
if (TemperatureToSet == (double)Command/10){
Serial.println(" OK");
return true;
}
else{
Serial.println(" FALSE");
return false;
}
}
void setup() {
Serial.begin(115200);
Wire.begin();
Wire.setClock(10000);
for (double d = 10.0; d < 130.0; d+=0.5){
SetTemperatureToController (d, 1);
delay(100);
}
}
void loop() {
}
Slave:
#include <Wire.h>
unsigned int Command;
char TwoBytes [2];
double TemperatureToSet;
byte EEPROM_WireAddress = 1;
void receiveEvent(byte bytes) {
//Прочитать команду
TwoBytes[0] = NULL;
TwoBytes[1] = NULL;
while (!Wire.available()) {
}
while (Wire.available()) {
TwoBytes[0] = Wire.read();
TwoBytes[1] = Wire.read();
while (Wire.available()) {
Wire.read();
}
}
Command = NULL;
Command = ((unsigned int)TwoBytes[0] << 8) + ((unsigned int)TwoBytes[1]);
//Записать температуру в TemperatureToSet
if (Command < 10000 && Command >= 100) {
TemperatureToSet = (double)Command / 10;
}
if (Command == 3) {
Serial.print(" && ");Serial.println(Command);
}
else {
Serial.print("Receiv: ");Serial.print(Command);
}
}
void requestEvent() {
//Отправить температуру из TemperatureToSet
if (Command == 3) {
Command = TemperatureToSet * 10;
Wire.write(Command >> 8);
Wire.write(Command & 0xFF);
Serial.print("Sended: ");Serial.println(Command);
Command = NULL;
}
}
void setup() {
Serial.begin(115200);
Wire.begin(EEPROM_WireAddress);
Wire.setClock(10000);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
}
void loop() {
}
Master serial monitor:
Sended: 100 && 3
Receiv: 100 OK
Sended: 105 && 3
Receiv: 105 OK
Sended: 110 && 3
Receiv: 110 OK
Sended: 115 && 3
Receiv: 115 OK
Sended: 120 && 3
Receiv: 120 OK
Sended: 125 && 3
Receiv: 125 OK
Sended: 130 && 3
Receiv: 125 FALSE
Sended: 135 && 3
Receiv: 125 FALSE
Sended: 140 && 3
Receiv: 125 FALSE
Sended: 145 && 3
Receiv: 125 FALSE
Sended: 150 && 3
Receiv: 125 FALSE
Sended: 155 && 3
Receiv: 125 FALSE
Sended: 160 && 3
Receiv: 125 FALSE
Sended: 165 && 3
Receiv: 125 FALSE
Sended: 170 && 3
Receiv: 125 FALSE
Sended: 175 && 3
Receiv: 125 FALSE
Sended: 180 && 3
Receiv: 125 FALSE
Sended: 185 && 3
Receiv: 125 FALSE
Sended: 190 && 3
Receiv: 125 FALSE
Sended: 195 && 3
Receiv: 125 FALSE
Sended: 200 && 3
Receiv: 125 FALSE
Sended: 205 && 3
Receiv: 125 FALSE
Sended: 210 && 3
Receiv: 125 FALSE
Sended: 215 && 3
Receiv: 125 FALSE
Sended: 220 && 3
Receiv: 125 FALSE
Sended: 225 && 3
Receiv: 125 FALSE
Sended: 230 && 3
Receiv: 125 FALSE
Sended: 235 && 3
Receiv: 125 FALSE
Sended: 240 && 3
Receiv: 125 FALSE
Sended: 245 && 3
Receiv: 125 FALSE
Sended: 250 && 3
Receiv: 125 FALSE
Sended: 255 && 3
Receiv: 125 FALSE
Sended: 260 && 3
Receiv: 260 OK
Sended: 265 && 3
Receiv: 265 OK
Sended: 270 && 3
Receiv: 270 OK
Sended: 275 && 3
Receiv: 275 OK
Sended: 280 && 3
Receiv: 280 OK
Sended: 285 && 3
Receiv: 285 OK
Sended: 290 && 3
Receiv: 290 OK
Sended: 295 && 3
Receiv: 295 OK
Sended: 300 && 3
Receiv: 300 OK
Sended: 305 && 3
Receiv: 305 OK
Sended: 310 && 3
Receiv: 310 OK
Sended: 315 && 3
Receiv: 315 OK
Sended: 320 && 3
Receiv: 320 OK
Sended: 325 && 3
Receiv: 325 OK
Sended: 330 && 3
Receiv: 330 OK
Sended: 335 && 3
Receiv: 335 OK
Sended: 340 && 3
Receiv: 340 OK
Sended: 345 && 3
Receiv: 345 OK
Sended: 350 && 3
Receiv: 350 OK
Sended: 355 && 3
Receiv: 355 OK
Sended: 360 && 3
Receiv: 360 OK
Sended: 365 && 3
Receiv: 365 OK
Sended: 370 && 3
Receiv: 370 OK
Sended: 375 && 3
Receiv: 375 OK
Sended: 380 && 3
Receiv: 380 OK
Sended: 385 && 3
Receiv: 65409 FALSE
Sended: 390 && 3
Receiv: 65414 FALSE
Sended: 395 && 3
Receiv: 65419 FALSE
Sended: 400 && 3
Receiv: 65424 FALSE
Sended: 405 && 3
Receiv: 65429 FALSE
Sended: 410 && 3
Receiv: 65434 FALSE
Sended: 415 && 3
Receiv: 65439 FALSE
Sended: 420 && 3
Receiv: 65444 FALSE
Sended: 425 && 3
Receiv: 65449 FALSE
Sended: 430 && 3
Receiv: 65454 FALSE
Sended: 435 && 3
Receiv: 65459 FALSE
Sended: 440 && 3
Receiv: 65464 FALSE
Sended: 445 && 3
Receiv: 65469 FALSE
Sended: 450 && 3
Receiv: 65474 FALSE
Sended: 455 && 3
Receiv: 65479 FALSE
Sended: 460 && 3
Receiv: 65484 FALSE
Sended: 465 && 3
Receiv: 65489 FALSE
Sended: 470 && 3
Receiv: 65494 FALSE
Sended: 475 && 3
Receiv: 65499 FALSE
Sended: 480 && 3
Receiv: 65504 FALSE
Sended: 485 && 3
Receiv: 65509 FALSE
Sended: 490 && 3
Receiv: 65514 FALSE
Sended: 495 && 3
Receiv: 65519 FALSE
Sended: 500 && 3
Receiv: 65524 FALSE
Sended: 505 && 3
Receiv: 65529 FALSE
Sended: 510 && 3
Receiv: 65534 FALSE
Sended: 515 && 3
Receiv: 515 OK
Sended: 520 && 3
Receiv: 520 OK
Sended: 525 && 3
Receiv: 525 OK
Sended: 530 && 3
Receiv: 530 OK
Sended: 535 && 3
Receiv: 535 OK
Sended: 540 && 3
Receiv: 540 OK
Sended: 545 && 3
Receiv: 545 OK
Sended: 550 && 3
Receiv: 550 OK
Sended: 555 && 3
Receiv: 555 OK
Sended: 560 && 3
Receiv: 560 OK
Sended: 565 && 3
Receiv: 565 OK
Sended: 570 && 3
Receiv: 570 OK
Sended: 575 && 3
Receiv: 575 OK
Sended: 580 && 3
Receiv: 580 OK
Sended: 585 && 3
Receiv: 585 OK
Sended: 590 && 3
Receiv: 590 OK
Sended: 595 && 3
Receiv: 595 OK
Sended: 600 && 3
Receiv: 600 OK
Sended: 605 && 3
Receiv: 605 OK
Sended: 610 && 3
Receiv: 610 OK
Sended: 615 && 3
Receiv: 615 OK
Sended: 620 && 3
Receiv: 620 OK
Sended: 625 && 3
Receiv: 625 OK
Sended: 630 && 3
Receiv: 630 OK
Sended: 635 && 3
Receiv: 635 OK
Sended: 640 && 3
Receiv: 128 FALSE
Sended: 645 && 3
Receiv: 133 FALSE
Sended: 650 && 3
Receiv: 138 FALSE
Sended: 655 && 3
Receiv: 143 FALSE
Sended: 660 && 3
Receiv: 148 FALSE
Sended: 665 && 3
Receiv: 153 FALSE
Sended: 670 && 3
Receiv: 158 FALSE
Sended: 675 && 3
Receiv: 163 FALSE
Sended: 680 && 3
Receiv: 168 FALSE
Sended: 685 && 3
Receiv: 173 FALSE
Sended: 690 && 3
Receiv: 178 FALSE
Sended: 695 && 3
Receiv: 183 FALSE
Sended: 700 && 3
Receiv: 188 FALSE
Sended: 705 && 3
Receiv: 193 FALSE
Sended: 710 && 3
Receiv: 198 FALSE
Sended: 715 && 3
Receiv: 203 FALSE
Sended: 720 && 3
Receiv: 208 FALSE
Sended: 725 && 3
Receiv: 213 FALSE
Sended: 730 && 3
Receiv: 218 FALSE
Sended: 735 && 3
Receiv: 223 FALSE
Sended: 740 && 3
Receiv: 228 FALSE
Sended: 745 && 3
Receiv: 233 FALSE
Sended: 750 && 3
Receiv: 238 FALSE
Sended: 755 && 3
Receiv: 243 FALSE
Sended: 760 && 3
Receiv: 248 FALSE
Sended: 765 && 3
Receiv: 253 FALSE
Sended: 770 && 3
Receiv: 770 OK
Sended: 775 && 3
Receiv: 775 OK
Sended: 780 && 3
Receiv: 780 OK
Sended: 785 && 3
Receiv: 785 OK
Sended: 790 && 3
Receiv: 790 OK
Sended: 795 && 3
Receiv: 795 OK
Sended: 800 && 3
Receiv: 800 OK
Sended: 805 && 3
Receiv: 805 OK
Sended: 810 && 3
Receiv: 810 OK
Sended: 815 && 3
Receiv: 815 OK
Sended: 820 && 3
Receiv: 820 OK
Sended: 825 && 3
Receiv: 825 OK
Sended: 830 && 3
Receiv: 830 OK
Sended: 835 && 3
Receiv: 835 OK
Sended: 840 && 3
Receiv: 840 OK
Sended: 845 && 3
Receiv: 845 OK
Sended: 850 && 3
Receiv: 850 OK
Sended: 855 && 3
Receiv: 855 OK
Sended: 860 && 3
Receiv: 860 OK
Sended: 865 && 3
Receiv: 865 OK
Sended: 870 && 3
Receiv: 870 OK
Sended: 875 && 3
Receiv: 875 OK
Sended: 880 && 3
Receiv: 880 OK
Sended: 885 && 3
Receiv: 885 OK
Sended: 890 && 3
Receiv: 890 OK
Sended: 895 && 3
Receiv: 895 OK
Sended: 900 && 3
Receiv: 388 FALSE
Sended: 905 && 3
Receiv: 393 FALSE
Sended: 910 && 3
Receiv: 398 FALSE
Sended: 915 && 3
Receiv: 403 FALSE
Sended: 920 && 3
Receiv: 408 FALSE
Sended: 925 && 3
Receiv: 413 FALSE
Sended: 930 && 3
Receiv: 418 FALSE
Sended: 935 && 3
Receiv: 423 FALSE
Sended: 940 && 3
Receiv: 428 FALSE
Sended: 945 && 3
Receiv: 433 FALSE
Sended: 950 && 3
Receiv: 438 FALSE
Sended: 955 && 3
Receiv: 443 FALSE
Sended: 960 && 3
Receiv: 448 FALSE
Sended: 965 && 3
Receiv: 453 FALSE
Sended: 970 && 3
Receiv: 458 FALSE
Sended: 975 && 3
Receiv: 463 FALSE
Sended: 980 && 3
Receiv: 468 FALSE
Sended: 985 && 3
Receiv: 473 FALSE
Sended: 990 && 3
Receiv: 478 FALSE
Sended: 995 && 3
Receiv: 483 FALSE
Sended: 1000 && 3
Receiv: 488 FALSE
Sended: 1005 && 3
Receiv: 493 FALSE
Sended: 1010 && 3
Receiv: 498 FALSE
Sended: 1015 && 3
Receiv: 503 FALSE
Sended: 1020 && 3
Receiv: 508 FALSE
Sended: 1025 && 3
Receiv: 1025 OK
Sended: 1030 && 3
Receiv: 1030 OK
Sended: 1035 && 3
Receiv: 1035 OK
Sended: 1040 && 3
Receiv: 1040 OK
Sended: 1045 && 3
Receiv: 1045 OK
Sended: 1050 && 3
Receiv: 1050 OK
Sended: 1055 && 3
Receiv: 1055 OK
Sended: 1060 && 3
Receiv: 1060 OK
Sended: 1065 && 3
Receiv: 1065 OK
Sended: 1070 && 3
Receiv: 1070 OK
Sended: 1075 && 3
Receiv: 1075 OK
Sended: 1080 && 3
Receiv: 1080 OK
Sended: 1085 && 3
Receiv: 1085 OK
Sended: 1090 && 3
Receiv: 1090 OK
Sended: 1095 && 3
Receiv: 1095 OK
Sended: 1100 && 3
Receiv: 1100 OK
Sended: 1105 && 3
Receiv: 1105 OK
Sended: 1110 && 3
Receiv: 1110 OK
Sended: 1115 && 3
Receiv: 1115 OK
Sended: 1120 && 3
Receiv: 1120 OK
Sended: 1125 && 3
Receiv: 1125 OK
Sended: 1130 && 3
Receiv: 1130 OK
Sended: 1135 && 3
Receiv: 1135 OK
Sended: 1140 && 3
Receiv: 1140 OK
Sended: 1145 && 3
Receiv: 1145 OK
Sended: 1150 && 3
Receiv: 1150 OK
Sended: 1155 && 3
Receiv: 643 FALSE
Sended: 1160 && 3
Receiv: 648 FALSE
Sended: 1165 && 3
Receiv: 653 FALSE
Sended: 1170 && 3
Receiv: 658 FALSE
Sended: 1175 && 3
Receiv: 663 FALSE
Sended: 1180 && 3
Receiv: 668 FALSE
Sended: 1185 && 3
Receiv: 673 FALSE
Sended: 1190 && 3
Receiv: 678 FALSE
Sended: 1195 && 3
Receiv: 683 FALSE
Sended: 1200 && 3
Receiv: 688 FALSE
Sended: 1205 && 3
Receiv: 693 FALSE
Sended: 1210 && 3
Receiv: 698 FALSE
Sended: 1215 && 3
Receiv: 703 FALSE
Sended: 1220 && 3
Receiv: 708 FALSE
Sended: 1225 && 3
Receiv: 713 FALSE
Sended: 1230 && 3
Receiv: 718 FALSE
Sended: 1235 && 3
Receiv: 723 FALSE
Sended: 1240 && 3
Receiv: 728 FALSE
Sended: 1245 && 3
Receiv: 733 FALSE
Sended: 1250 && 3
Receiv: 738 FALSE
Sended: 1255 && 3
Receiv: 743 FALSE
Sended: 1260 && 3
Receiv: 748 FALSE
Sended: 1265 && 3
Receiv: 753 FALSE
Sended: 1270 && 3
Receiv: 758 FALSE
Sended: 1275 && 3
Receiv: 763 FALSE
Sended: 1280 && 3
Receiv: 1280 OK
Sended: 1285 && 3
Receiv: 1285 OK
Sended: 1290 && 3
Receiv: 1290 OK
Sended: 1295 && 3
Receiv: 1295 OK
Slave serial monitor:
Receiv: 100 && 3
Sended: 100
Receiv: 105 && 3
Sended: 105
Receiv: 110 && 3
Sended: 110
Receiv: 115 && 3
Sended: 115
Receiv: 120 && 3
Sended: 120
Receiv: 125 && 3
Sended: 125
Receiv: 65410 && 3
Sended: 125
Receiv: 65415 && 3
Sended: 125
Receiv: 65420 && 3
Sended: 125
Receiv: 65425 && 3
Sended: 125
Receiv: 65430 && 3
Sended: 125
Receiv: 65435 && 3
Sended: 125
Receiv: 65440 && 3
Sended: 125
Receiv: 65445 && 3
Sended: 125
Receiv: 65450 && 3
Sended: 125
Receiv: 65455 && 3
Sended: 125
Receiv: 65460 && 3
Sended: 125
Receiv: 65465 && 3
Sended: 125
Receiv: 65470 && 3
Sended: 125
Receiv: 65475 && 3
Sended: 125
Receiv: 65480 && 3
Sended: 125
Receiv: 65485 && 3
Sended: 125
Receiv: 65490 && 3
Sended: 125
Receiv: 65495 && 3
Sended: 125
Receiv: 65500 && 3
Sended: 125
Receiv: 65505 && 3
Sended: 125
Receiv: 65510 && 3
Sended: 125
Receiv: 65515 && 3
Sended: 125
Receiv: 65520 && 3
Sended: 125
Receiv: 65525 && 3
Sended: 125
Receiv: 65530 && 3
Sended: 125
Receiv: 65535 && 3
Sended: 125
Receiv: 260 && 3
Sended: 260
Receiv: 265 && 3
Sended: 265
Receiv: 270 && 3
Sended: 270
Receiv: 275 && 3
Sended: 275
Receiv: 280 && 3
Sended: 280
Receiv: 285 && 3
Sended: 285
Receiv: 290 && 3
Sended: 290
Receiv: 295 && 3
Sended: 295
Receiv: 300 && 3
Sended: 300
Receiv: 305 && 3
Sended: 305
Receiv: 310 && 3
Sended: 310
Receiv: 315 && 3
Sended: 315
Receiv: 320 && 3
Sended: 320
Receiv: 325 && 3
Sended: 325
Receiv: 330 && 3
Sended: 330
Receiv: 335 && 3
Sended: 335
Receiv: 340 && 3
Sended: 340
Receiv: 345 && 3
Sended: 345
Receiv: 350 && 3
Sended: 350
Receiv: 355 && 3
Sended: 355
Receiv: 360 && 3
Sended: 360
Receiv: 365 && 3
Sended: 365
Receiv: 370 && 3
Sended: 370
Receiv: 375 && 3
Sended: 375
Receiv: 380 && 3
Sended: 380
Receiv: 129 && 3
Sended: 129
Receiv: 134 && 3
Sended: 134
Receiv: 139 && 3
Sended: 139
Receiv: 144 && 3
Sended: 144
Receiv: 149 && 3
Sended: 149
Receiv: 154 && 3
Sended: 154
Receiv: 159 && 3
Sended: 159
Receiv: 164 && 3
Sended: 164
Receiv: 169 && 3
Sended: 169
Receiv: 174 && 3
Sended: 174
Receiv: 179 && 3
Sended: 179
Receiv: 184 && 3
Sended: 184
Receiv: 189 && 3
Sended: 189
Receiv: 194 && 3
Sended: 194
Receiv: 199 && 3
Sended: 199
Receiv: 204 && 3
Sended: 204
Receiv: 209 && 3
Sended: 209
Receiv: 214 && 3
Sended: 214
Receiv: 219 && 3
Sended: 219
Receiv: 224 && 3
Sended: 224
Receiv: 229 && 3
Sended: 229
Receiv: 234 && 3
Sended: 234
Receiv: 100 && 3
Sended: 100
Receiv: 105 && 3
Sended: 105
Receiv: 110 && 3
Sended: 110
Receiv: 115 && 3
Sended: 115
Receiv: 120 && 3
Sended: 120
Receiv: 125 && 3
Sended: 125
Receiv: 65410 && 3
Sended: 125
Receiv: 65415 && 3
Sended: 125
Receiv: 65420 && 3
Sended: 125
Receiv: 65425 && 3
Sended: 125
Receiv: 65430 && 3
Sended: 125
Receiv: 65435 && 3
Sended: 125
Receiv: 65440 && 3
Sended: 125
Receiv: 65445 && 3
Sended: 125
Receiv: 65450 && 3
Sended: 125
Receiv: 65455 && 3
Sended: 125
Receiv: 65460 && 3
Sended: 125
Receiv: 65465 && 3
Sended: 125
Receiv: 65470 && 3
Sended: 125
Receiv: 65475 && 3
Sended: 125
Receiv: 65480 && 3
Sended: 125
Receiv: 65485 && 3
Sended: 125
Receiv: 65490 && 3
Sended: 125
Receiv: 65495 && 3
Sended: 125
Receiv: 65500 && 3
Sended: 125
Receiv: 65505 && 3
Sended: 125
Receiv: 65510 && 3
Sended: 125
Receiv: 65515 && 3
Sended: 125
Receiv: 65520 && 3
Sended: 125
Receiv: 65525 && 3
Sended: 125
Receiv: 65530 && 3
Sended: 125
Receiv: 65535 && 3
Sended: 125
Receiv: 260 && 3
Sended: 260
Receiv: 265 && 3
Sended: 265
Receiv: 270 && 3
Sended: 270
Receiv: 275 && 3
Sended: 275
Receiv: 280 && 3
Sended: 280
Receiv: 285 && 3
Sended: 285
Receiv: 290 && 3
Sended: 290
Receiv: 295 && 3
Sended: 295
Receiv: 300 && 3
Sended: 300
Receiv: 305 && 3
Sended: 305
Receiv: 310 && 3
Sended: 310
Receiv: 315 && 3
Sended: 315
Receiv: 320 && 3
Sended: 320
Receiv: 325 && 3
Sended: 325
Receiv: 330 && 3
Sended: 330
Receiv: 335 && 3
Sended: 335
Receiv: 340 && 3
Sended: 340
Receiv: 345 && 3
Sended: 345
Receiv: 350 && 3
Sended: 350
Receiv: 355 && 3
Sended: 355
Receiv: 360 && 3
Sended: 360
Receiv: 365 && 3
Sended: 365
Receiv: 370 && 3
Sended: 370
Receiv: 375 && 3
Sended: 375
Receiv: 380 && 3
Sended: 380
Receiv: 129 && 3
Sended: 129
Receiv: 134 && 3
Sended: 134
Receiv: 139 && 3
Sended: 139
Receiv: 144 && 3
Sended: 144
Receiv: 149 && 3
Sended: 149
Receiv: 154 && 3
Sended: 154
Receiv: 159 && 3
Sended: 159
Receiv: 164 && 3
Sended: 164
Receiv: 169 && 3
Sended: 169
Receiv: 174 && 3
Sended: 174
Receiv: 179 && 3
Sended: 179
Receiv: 184 && 3
Sended: 184
Receiv: 189 && 3
Sended: 189
Receiv: 194 && 3
Sended: 194
Receiv: 199 && 3
Sended: 199
Receiv: 204 && 3
Sended: 204
Receiv: 209 && 3
Sended: 209
Receiv: 214 && 3
Sended: 214
Receiv: 219 && 3
Sended: 219
Receiv: 224 && 3
Sended: 224
Receiv: 229 && 3
Sended: 229
Receiv: 234 && 3
Sended: 234
Receiv: 239 && 3
Sended: 239
Receiv: 244 && 3
Sended: 244
Receiv: 249 && 3
Sended: 249
Receiv: 254 && 3
Sended: 254
Receiv: 515 && 3
Sended: 515
Receiv: 520 && 3
Sended: 520
Receiv: 525 && 3
Sended: 525
Receiv: 530 && 3
Sended: 530
Receiv: 535 && 3
Sended: 535
Receiv: 540 && 3
Sended: 540
Receiv: 545 && 3
Sended: 545
Receiv: 550 && 3
Sended: 550
Receiv: 555 && 3
Sended: 555
Receiv: 560 && 3
Sended: 560
Receiv: 565 && 3
Sended: 565
Receiv: 570 && 3
Sended: 570
Receiv: 575 && 3
Sended: 575
Receiv: 580 && 3
Sended: 580
Receiv: 585 && 3
Sended: 585
Receiv: 590 && 3
Sended: 590
Receiv: 595 && 3
Sended: 595
Receiv: 600 && 3
Sended: 600
Receiv: 605 && 3
Sended: 605
Receiv: 610 && 3
Sended: 610
Receiv: 615 && 3
Sended: 615
Receiv: 620 && 3
Sended: 620
Receiv: 625 && 3
Sended: 625
Receiv: 630 && 3
Sended: 630
Receiv: 635 && 3
Sended: 635
Receiv: 384 && 3
Sended: 384
Receiv: 389 && 3
Sended: 389
Receiv: 394 && 3
Sended: 394
Receiv: 399 && 3
Sended: 399
Receiv: 404 && 3
Sended: 404
Receiv: 409 && 3
Sended: 409
Receiv: 414 && 3
Sended: 414
Receiv: 419 && 3
Sended: 419
Receiv: 424 && 3
Sended: 424
Receiv: 429 && 3
Sended: 429
Receiv: 434 && 3
Sended: 434
Receiv: 439 && 3
Sended: 439
Receiv: 444 && 3
Sended: 444
Receiv: 449 && 3
Sended: 449
Receiv: 454 && 3
Sended: 454
Receiv: 459 && 3
Sended: 459
Receiv: 464 && 3
Sended: 464
Receiv: 469 && 3
Sended: 469
Receiv: 474 && 3
Sended: 474
Receiv: 479 && 3
Sended: 479
Receiv: 484 && 3
Sended: 484
Receiv: 489 && 3
Sended: 489
Receiv: 494 && 3
Sended: 494
Receiv: 499 && 3
Sended: 499
Receiv: 504 && 3
Sended: 504
Receiv: 509 && 3
Sended: 509
Receiv: 770 && 3
Sended: 770
Receiv: 775 && 3
Sended: 775
Receiv: 780 && 3
Sended: 780
Receiv: 785 && 3
Sended: 785
Receiv: 790 && 3
Sended: 790
Receiv: 795 && 3
Sended: 795
Receiv: 800 && 3
Sended: 800
Receiv: 805 && 3
Sended: 805
Receiv: 810 && 3
Sended: 810
Receiv: 815 && 3
Sended: 815
Receiv: 820 && 3
Sended: 820
Receiv: 825 && 3
Sended: 825
Receiv: 830 && 3
Sended: 830
Receiv: 835 && 3
Sended: 835
Receiv: 840 && 3
Sended: 840
Receiv: 845 && 3
Sended: 845
Receiv: 850 && 3
Sended: 850
Receiv: 855 && 3
Sended: 855
Receiv: 860 && 3
Sended: 860
Receiv: 865 && 3
Sended: 865
Receiv: 870 && 3
Sended: 870
Receiv: 875 && 3
Sended: 875
Receiv: 880 && 3
Sended: 880
Receiv: 885 && 3
Sended: 885
Receiv: 890 && 3
Sended: 890
Receiv: 895 && 3
Sended: 895
Receiv: 644 && 3
Sended: 644
Receiv: 649 && 3
Sended: 649
Receiv: 654 && 3
Sended: 654
Receiv: 659 && 3
Sended: 659
Receiv: 664 && 3
Sended: 664
Receiv: 669 && 3
Sended: 669
Receiv: 674 && 3
Sended: 674
Receiv: 679 && 3
Sended: 679
Receiv: 684 && 3
Sended: 684
Receiv: 689 && 3
Sended: 689
Receiv: 694 && 3
Sended: 694
Receiv: 699 && 3
Sended: 699
Receiv: 704 && 3
Sended: 704
Receiv: 709 && 3
Sended: 709
Receiv: 714 && 3
Sended: 714
Receiv: 719 && 3
Sended: 719
Receiv: 724 && 3
Sended: 724
Receiv: 729 && 3
Sended: 729
Receiv: 734 && 3
Sended: 734
Receiv: 739 && 3
Sended: 739
Receiv: 744 && 3
Sended: 744
Receiv: 749 && 3
Sended: 749
Receiv: 754 && 3
Sended: 754
Receiv: 759 && 3
Sended: 759
Receiv: 764 && 3
Sended: 764
Receiv: 1025 && 3
Sended: 1025
Receiv: 1030 && 3
Sended: 1030
Receiv: 1035 && 3
Sended: 1035
Receiv: 1040 && 3
Sended: 1040
Receiv: 1045 && 3
Sended: 1045
Receiv: 1050 && 3
Sended: 1050
Receiv: 1055 && 3
Sended: 1055
Receiv: 1060 && 3
Sended: 1060
Receiv: 1065 && 3
Sended: 1065
Receiv: 1070 && 3
Sended: 1070
Receiv: 1075 && 3
Sended: 1075
Receiv: 1080 && 3
Sended: 1080
Receiv: 1085 && 3
Sended: 1085
Receiv: 1090 && 3
Sended: 1090
Receiv: 1095 && 3
Sended: 1095
Receiv: 1100 && 3
Sended: 1100
Receiv: 1105 && 3
Sended: 1105
Receiv: 1110 && 3
Sended: 1110
Receiv: 1115 && 3
Sended: 1115
Receiv: 1120 && 3
Sended: 1120
Receiv: 1125 && 3
Sended: 1125
Receiv: 1130 && 3
Sended: 1130
Receiv: 1135 && 3
Sended: 1135
Receiv: 1140 && 3
Sended: 1140
Receiv: 1145 && 3
Sended: 1145
Receiv: 1150 && 3
Sended: 1150
Receiv: 899 && 3
Sended: 899
Receiv: 904 && 3
Sended: 904
Receiv: 909 && 3
Sended: 909
Receiv: 914 && 3
Sended: 914
Receiv: 919 && 3
Sended: 919
Receiv: 924 && 3
Sended: 924
Receiv: 929 && 3
Sended: 929
Receiv: 934 && 3
Sended: 934
Receiv: 939 && 3
Sended: 939
Receiv: 944 && 3
Sended: 944
Receiv: 949 && 3
Sended: 949
Receiv: 954 && 3
Sended: 954
Receiv: 959 && 3
Sended: 959
Receiv: 964 && 3
Sended: 964
Receiv: 969 && 3
Sended: 969
Receiv: 974 && 3
Sended: 974
Receiv: 979 && 3
Sended: 979
Receiv: 984 && 3
Sended: 984
Receiv: 989 && 3
Sended: 989
Receiv: 994 && 3
Sended: 994
Receiv: 999 && 3
Sended: 999
Receiv: 1004 && 3
Sended: 1004
Receiv: 1009 && 3
Sended: 1009
Receiv: 1014 && 3
Sended: 1014
Receiv: 1019 && 3
Sended: 1019
Receiv: 1280 && 3
Sended: 1280
Receiv: 1285 && 3
Sended: 1285
Receiv: 1290 && 3
Sended: 1290
Receiv: 1295 && 3
Sended: 1295
Вот аппаратная часть. Лучше не сделать.
Очень врядли кто-то захочет разбираться в коде. Да и незачем, там кроме математики ничего нету.
Использую пару библиотек
#include <PID_v1.h>
#include <Thermistor.h>
#include <NTC_Thermistor.h>
#include <Wire.h>
#include <EEPROM.h>
Программа работает просто. Рассчитывает мощность нагрева чтобы достичь заданой температуры опираясь на показания ADC.
В мастер коде используется только то, что написал в 1 посте (Master code: && Тестовый код:).
К на i2c еще подключено 2 девайса, RTC и тачскрин. Оба используются без прерываний, мастер контроллером.
Связь между контроллерами по i2c.
Master задает и контролирует параметры у 6 Slaves.
При тестовом прогоне кода обнаружилась НЁХ.
Функция SetTemperatureToController возвращает false.
Похоже что линия i2c перестает работать с некоторой периодичностью на 0,1 сек.
В чем может быть проблема?
Master code:
unsigned int Command = 0;
char TwoBytes [2];
bool SetTemperatureToController (double TemperatureToSet, byte ControllerToSet) {
//Отправить температуру
Command = TemperatureToSet * 10;
Wire.beginTransmission(ControllerToSet);
Wire.write(Command >> 8);
Wire.write(Command & 0xFF);
Wire.endTransmission();
//Команда на получение температуры
Command = 3;
Wire.beginTransmission(ControllerToSet);
Wire.write(Command >> 8);
Wire.write(Command & 0xFF);
Wire.endTransmission();
//Получить температуру
Wire.requestFrom(ControllerToSet, 2);
TwoBytes[0] = NULL;
TwoBytes[1] = NULL;
TwoBytes[0] = Wire.read();
TwoBytes[1] = Wire.read();
Command = 0;
Command = ((unsigned int)TwoBytes[0] << 8) + ((unsigned int)TwoBytes[1]);
//Проверка на успешное задание температуры
if (TemperatureToSet == (double)Command/10) return true;
else return false;
}
Slave code:
unsigned int Command;
char TwoBytes [2];
void receiveEvent(byte bytes) {
//Прочитать команду
TwoBytes[0] = NULL;
TwoBytes[1] = NULL;
if (bytes == 2) {
TwoBytes[0] = Wire.read();
TwoBytes[1] = Wire.read();
}
Command = NULL;
Command = ((unsigned int)TwoBytes[0] << 8) + ((unsigned int)TwoBytes[1]);
//Serial.println (Command);
//Записать температуру в TemperatureToSet
if (Command < 10000 && Command >= 100) {
TemperatureToSet = (double)Command / 10;
}
}
void requestEvent() {
//Отправить температуру из TemperatureToSet
if (Command == 3) {
Command = TemperatureToSet*10;
Wire.write(Command >> 8);
Wire.write(Command & 0xFF);
Command = NULL;
}
}
Тестовый код:
for (double d = 10.0; d < 130.0; d+=0.5){
if (SetTemperatureToController (d, 1)){
Serial.print(millis()); Serial.print(": "); Serial.println(d);
delay(100);
}
else {
Serial.print(millis()); Serial.print(": "); Serial.println("false");
}
}
Что получаю в терминале:
654: 10.00
755: 10.50
857: 11.00
959: 11.50
1060: 12.00
1162: 12.50
1264: false
1265: false
1266: false
1267: false
1269: false
1270: false
1271: false
1273: false
1274: false
1275: false
1277: false
1278: false
1280: false
1282: false
1283: false
1284: false
1285: false
1287: false
1288: false
1289: false
1290: false
1292: false
1293: false
1294: false
1296: false
1297: false
1298: 26.00
1400: 26.50
1502: 27.00
1603: 27.50
1705: 28.00
1807: 28.50
1908: 29.00
2011: 29.50
2112: 30.00
2213: 30.50
2316: 31.00
2417: 31.50
2519: 32.00
2621: 32.50
2722: 33.00
2824: 33.50
2926: 34.00
3027: 34.50
3129: 35.00
3231: 35.50
3333: 36.00
3434: 36.50
3536: 37.00
3638: 37.50
3739: 38.00
3842: false
3843: false
3844: false
3845: false
3847: false
3848: false
3849: false
3851: false
3852: false
3853: false
3855: false
3856: false
3857: false
3859: false
3860: false
3861: false
3863: false
3864: false
3865: false
3866: false
3868: false
3869: false
3870: false
3872: false
3873: false
3874: false
3876: 51.50
3978: 52.00
4079: 52.50
4182: 53.00
4283: 53.50
4384: 54.00
4487: 54.50
4588: 55.00
4689: 55.50
4792: 56.00
4893: 56.50
4995: 57.00
5097: 57.50
5198: 58.00
5300: 58.50
5402: 59.00
5504: 59.50
5605: 60.00
5707: 60.50
5809: 61.00
5910: 61.50
6012: 62.00
6114: 62.50
6215: 63.00
6318: 63.50
6419: false
6420: false
6421: false
6423: false
6424: false
6425: false
6427: false
6428: false
6429: false
6431: false
6432: false
6433: false
6435: false
6436: false
6437: false
6439: false
6440: false
6441: false
6443: false
6445: false
6446: false
6447: false
6449: false
6450: false
6451: false
6453: false
6454: 77.00
6555: 77.50
6658: 78.00
6759: 78.50
6860: 79.00
6963: 79.50
7064: 80.00
7165: 80.50
7268: 81.00
7369: 81.50
7471: 82.00
7573: 82.50
7674: 83.00
7776: 83.50
7878: 84.00
7980: 84.50
8081: 85.00
8183: 85.50
8285: 86.00
8386: 86.50
8488: 87.00
8590: 87.50
8691: 88.00
8794: 88.50
8895: 89.00
8996: 89.50
9099: false
9100: false
9101: false
9103: false
9104: false
9105: false
9106: false
9108: false
9109: false
9110: false
9112: false
9113: false
9114: false
9116: false
9117: false
9118: false
9120: false
9121: false
9122: false
9124: false
9125: false
9126: false
9127: false
9129: false
9131: false
9132: 102.50
9234: 103.00
9335: 103.50
9437: 104.00
9539: 104.50
9640: 105.00
9742: 105.50
9844: 106.00
9946: 106.50
10048: 107.00
10149: 107.50
10251: 108.00
10353: 108.50
10455: 109.00
10557: 109.50
10658: 110.00
10761: 110.50
10862: 111.00
10963: 111.50
11066: 112.00
11167: 112.50
11270: 113.00
11371: 113.50
11473: 114.00
11575: 114.50
11676: 115.00
11779: false
11780: false
11782: false
11783: false
11784: false
11786: false
11787: false
11788: false
11790: false
11791: false
11792: false
11794: false
11795: false
11797: false
11798: false
11799: false
11801: false
11802: false
11803: false
11804: false
11806: false
11807: false
11809: false
11810: false
11811: false
11813: 128.00
11915: 128.50
12017: 129.00
12119: 129.50
Подсказали на другом форуме:
В библиотеке можно подправить
// Wait a fix number of cycles till conversion is complete (based on IC datasheet)
switch (*bitResolution)
{
case 9:
delay(94);
break;
case 10:
delay(188);
break;
case 11:
delay(375);
break;
case 12:
default:
delay(750);
break;
}
Сменил задержку до 100 мсек. Полет нормальный, прибор быстро набирает температуру и быстро стабилизирует ее до максимальных +/-0,06 градуса.
Температуру вроде бы показывает правильную. Интересно, как повлияло на работу программы датчика такое изменение температуры.
Работаю над неким проэктом где очень важно максимально точно поддерживать температуру. Столкнулся с проблемой очень медленной работы, из-за чего появляются колебания температуры.
Для примера есть следующий код. Программа снимает температуру с двух датчиков и выдает количество затраченного времени для 9, 10, 11 и 12 bit разрешения.
Используются библиотеки OneWire и DallasTemperature.
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = {0x28, 0xFA, 0xAB, 0x8C, 0x06, 0x00, 0x00, 0xFA};
DeviceAddress outsideThermometer = {0x28, 0x17, 0x1C, 0x8C, 0x06, 0x00, 0x00, 0x87};
void setup() {
Serial.begin(9600);
sensors.begin();
}
//Мигнуть диодом 100000 раз и вывести инфо о времени исполнения
void loop() {
double temp1;
double temp2;
unsigned long start ;
unsigned long i ;
Serial.print("requestTemperaturesByAddress + getTempC test, 12 bit: ") ;
sensors.setResolution(insideThermometer, 12);
sensors.setResolution(outsideThermometer, 12);
start = millis() ;
for (i = 0 ; i < 10 ; i++)
{
sensors.requestTemperaturesByAddress(insideThermometer);
temp1 = sensors.getTempC(insideThermometer);
sensors.requestTemperaturesByAddress(outsideThermometer);
temp2 = sensors.getTempC(outsideThermometer);
}
Serial.print(millis() - start) ;
Serial.println(" msec (10 calls)") ;
delay(2000);
Serial.print("requestTemperaturesByAddress + getTempC test, 11 bit: ") ;
sensors.setResolution(insideThermometer, 11);
sensors.setResolution(outsideThermometer, 11);
start = millis() ;
for (i = 0 ; i < 10 ; i++)
{
sensors.requestTemperaturesByAddress(insideThermometer);
temp1 = sensors.getTempC(insideThermometer);
sensors.requestTemperaturesByAddress(outsideThermometer);
temp2 = sensors.getTempC(outsideThermometer);
}
Serial.print(millis() - start) ;
Serial.println(" msec (10 calls)") ;
delay(2000);
Serial.print("requestTemperaturesByAddress + getTempC test, 10 bit: ") ;
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);
start = millis() ;
for (i = 0 ; i < 10 ; i++)
{
sensors.requestTemperaturesByAddress(insideThermometer);
temp1 = sensors.getTempC(insideThermometer);
sensors.requestTemperaturesByAddress(outsideThermometer);
temp2 = sensors.getTempC(outsideThermometer);
}
Serial.print(millis() - start) ;
Serial.println(" msec (10 calls)") ;
delay(2000);
Serial.print("requestTemperaturesByAddress + getTempC test, 9 bit: ") ;
sensors.setResolution(insideThermometer, 9);
sensors.setResolution(outsideThermometer, 9);
start = millis() ;
for (i = 0 ; i < 10 ; i++)
{
sensors.requestTemperaturesByAddress(insideThermometer);
temp1 = sensors.getTempC(insideThermometer);
sensors.requestTemperaturesByAddress(outsideThermometer);
temp2 = sensors.getTempC(outsideThermometer);
}
Serial.print(millis() - start) ;
Serial.println(" msec (10 calls)") ;
delay(2000);
}
Что из этого имеем:
requestTemperaturesByAddress + getTempC test, 12 bit: 16166 msec (10 calls) - 808,3 msec на снятие температуры с 1 датчика
requestTemperaturesByAddress + getTempC test, 11 bit: 8666 msec (10 calls) - 433,3 msec на снятие температуры с 1 датчика
requestTemperaturesByAddress + getTempC test, 10 bit: 4927 msec (10 calls) - 246.35 msec на снятие температуры с 1 датчика
requestTemperaturesByAddress + getTempC test, 9 bit: 3046 msec (10 calls) - 152,3 msec на снятие температуры с 1 датчика
Необходимо добиться чтобы при разрешении в 12 bit температура измерялась намного быстрее.
Прошу помощи!
Сторінки 1