Hallo, ich habe ein interessantes Problem:
ich habe mir für den Uno ein kleines Programm zusammengestellt, dass 6 DS18B20 ausliest und dann die Messwerte als Modbus-RTU-Slave zur Verfügung stellt.
Das funktioniert einwandfrei, wenn ich die Sensoren unmittelbar am Uno anschließe (Pullup 4,7k). Differenz der Sensoren 0,1K (alle 6 als Bündel zusammen)
Wenn ich die Sensorik an eine lange Busleitung (ca. 70m) als Linie anschließe (Pullup 1,56k) werden die Sensoren ebenfalls noch ausgelesen, allerdings weichen die Messwerte dann bis zu 2,8K voneinander ab. Der Messort und das Programm sind immer noch identisch.
Spiele ich bei gleichem Setup, das Beispielprogramm DS18x20 aus der OneWire-Bibliothek ein, ermittelt dieses die richtigen Messwerte! Es werden keine CRC-Fehler erkannt. Die Hardware scheint also zu funktionieren!
Allerdings liefert mein eigenes Programm andere Werte, also kann es doch nur noch ein Timing-Problem innerhalb des Controllers/Programm sein, oder?
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ModbusRtu.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 3
#define TXEN 2
//
uint16_t au16data[6];
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Aktivieren des ModBus-Slave
Modbus slave(1, 0, TXEN); // this is slave @1 and RS-485
// Feste Zuordnung der Sensoren über die Seriennummer
DeviceAddress Sensor0 = {0x28, 0xAA, 0xBA, 0x34, 0x13, 0x13, 0x01, 0x70};
DeviceAddress Sensor1 = {0x28, 0xAA, 0x7C, 0x35, 0x13, 0x13, 0x01, 0x41};
DeviceAddress Sensor2 = {0x28, 0xAA, 0x7A, 0x35, 0x13, 0x13, 0x01, 0xDD};
DeviceAddress Sensor3 = {0x28, 0xAA, 0x15, 0x25, 0x13, 0x13, 0x01, 0x9B};
DeviceAddress Sensor4 = {0x28, 0xAA, 0xA7, 0x32, 0x13, 0x13, 0x01, 0xE9};
DeviceAddress Sensor5 = {0x28, 0xAA, 0xD7, 0x2C, 0x13, 0x13, 0x01, 0xA9};
/*
The setup function. We only start the sensors here
*/
void setup(void)
{
slave.begin( 9600 ); // baud-rate at 19200
// Start up the library
sensors.begin();
}
/*
Main function, get and show the temperature
*/
void loop(void)
{
sensors.requestTemperatures(); // Send the command to get temperatures
float modbuswert_float_0 = sensors.getTempC(Sensor0);
au16data[0] = modbuswert_float_0 * 1000;
float modbuswert_float_1 = sensors.getTempC(Sensor1);
au16data[1] = modbuswert_float_1 * 1000;
float modbuswert_float_2 = sensors.getTempC(Sensor2);
au16data[2] = modbuswert_float_2 * 1000;
float modbuswert_float_3 = sensors.getTempC(Sensor3);
au16data[3] = modbuswert_float_3 * 1000;
float modbuswert_float_4 = sensors.getTempC(Sensor4);
au16data[4] = modbuswert_float_4 * 1000;
float modbuswert_float_5 = sensors.getTempC(Sensor5);
au16data[5] = modbuswert_float_5 * 1000;
slave.poll( au16data, 6 );
}
Grüße Alex