Hallo, ich versuche mit einem Arduino Uno und dem ENC28j60 Modul einen Modbus Slave zu realisieren, nur will das Ganze nicht so klappen.
Hier mal mein Code.
/*
Modbus-Arduino Example - Switch (Modbus IP ENC28J60)
Copyright by André Sarmento Barbosa
http://github.com/andresarmento/modbus-arduino
*/
#include <EtherCard.h>
#include <Modbus.h>
#include <ModbusIP_ENC28J60.h>
//Modbus Registers Offsets (0-9999)
const int SWITCH_ISTS = 100;
//Used Pins
const int switchPin = 2;
//ModbusIP object
ModbusIP mb;
void setup() {
// The media access control (ethernet hardware) address for the shield
byte mac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
// The IP address for the shield
byte ip[] = { 192, 168, 0, 101 };
byte dns[] = { 0, 0, 0, 0 };
byte ipgw[] = { 192, 168, 0, 1 };
byte subnet[] = { 255, 255, 255, 0};
//Config Modbus IP
mb.config(mac, ip, dns, ipgw, subnet);
//Set ledPin mode
pinMode(switchPin, INPUT);
// Add SWITCH_ISTS register - Use addIsts() for digital inputs
mb.addIsts(SWITCH_ISTS);
}
void loop() {
//Call once inside loop() - all magic here
mb.task();
//Attach switchPin to SWITCH_ISTS register
mb.Ists(SWITCH_ISTS, digitalRead(switchPin));
}
Wenn ich das Beispiel “backSoon” verwende kommt der Arduino in Netzwerk und kann angepingt werden, wenn ich allerdings den Code für den Modbus verwende, kommt der Arduino nicht mal mehr ins Netzwerk. Ich weis nicht mehr weiter.
Hier hab ich die Anleitung her: http://domoticx.com/module-ethernet-lan-netwerk-enc28j60-modbus-tcp-ip-slave/
Ich hoffe Ihr könnt mir weiter helfen.
Mit freundlichen Grüßen,
Stefan K.