Harisha
hi ,
i am working seeduino arch mix board i made it has Arduino compatible by running Arduino boot loader in that now i implemented some how digital inputs ,outputs,analog input and output with pwm now the thing is i need to implement modbus communication that how board works as master and for slave i can use slave emulator for communication i don't know how to implement this and do i need to do any changes in my hal code .than tell me how can we implement .
 
Note: i am using openplc editor version 4.1.4
  1. is there any tutorial or document related to implementation of modbus rtu communication .
  2. and also i have another question what are the peripheral we can explore in openplc rather than digital i/O and analog i/o,pwm,timers .
  3. is modbus in openplc(our board) works as master or slave?
  4. also for this do we need hardware rs485 transceiver in our board ?
 
  1. #include <stdlib.h>
    #include <stdio.h>
    extern "C" {
    #include "openplc.h"
    }
    #include "Arduino.h"
    #include "../examples/Baremetal/defines.h"
    // ================= PIN MAPPING =================
    // Digital Inputs (J3 connector pins)
    uint8_t pinMask_DIN[] = { J4_4, J4_5,J4_10,J4_11,J3_17,J3_16};
    // Analog Inputs (REAL hardware pins from variant.h)
    uint8_t pinMask_AIN[] = {AD1_3,AD1_4};
    // Digital Outputs (J4 connector pins)
    uint8_t pinMask_DOUT[] = {J4_7,J4_6,USER_LED_B,J4_8,USER_LED_R,USER_LED_G,J4_16,J4_17};
    // Analog Outputs (not used currently)
    uint8_t pinMask_AOUT[] = {J4_8,J4_9,AD2_9,AD2_10};

    // ================= HARDWARE INIT =================
    void hardwareInit()
    {
    // Configure digital inputs
    for (int i = 0; i < NUM_DISCRETE_INPUT; i++)
    {
    pinMode(pinMask_DIN[i], INPUT);
    }
    // Configure analog inputs
    for (int i = 0; i < NUM_ANALOG_INPUT; i++)
    {
    pinMode(pinMask_AIN[i], INPUT);
    }
    // Configure digital outputs
    for (int i = 0; i < NUM_DISCRETE_OUTPUT; i++)
    {
    pinMode(pinMask_DOUT[i], OUTPUT);
    }
    // Configure analog outputs
    for (int i = 0; i < NUM_ANALOG_OUTPUT; i++)
    {
    pinMode(pinMask_AOUT[i], OUTPUT);
    }
    }

    // ================= READ INPUTS =================
    void updateInputBuffers()
    {
    // Read digital inputs
    for (int i = 0; i < NUM_DISCRETE_INPUT; i++)
    {
    if (bool_input[i / 8][i % 8] != NULL)
    {
    *bool_input[i / 8][i % 8] = digitalRead(pinMask_DIN[i]);
    }
    }
    // Read analog inputs
    for (int i = 0; i < NUM_ANALOG_INPUT; i++)
    {
    if (int_input[i] != NULL)
    {
    /* *int_input[i] = analogRead(pinMask_AIN[i]);*/
    int raw = analogRead(pinMask_AIN[0]);
    *int_input[0] = raw;
    }
    }
    }

    // ================= WRITE OUTPUTS =================
    void updateOutputBuffers()
    {
    // Write digital outputs
    for (int i = 0; i < NUM_DISCRETE_OUTPUT; i++)
    {
    if (bool_output[i / 8][i % 8] != NULL)
    {
    digitalWrite(pinMask_DOUT[i], *bool_output[i / 8][i % 8]);
    }
    }
    for (int i = 0; i < NUM_ANALOG_OUTPUT; i++)
    {
    if (int_output[i] != NULL)
    {
    int raw = *int_output[i]; // 0–4095
    int pwm = map(raw, 0, 4095, 0, 255);
    analogWrite(pinMask_AOUT[i], pwm);
    }
    }
    }
thiagoralves
OpenPLC does not support Modbus master on microcontrollers. To enable Modbus slave all you have to do is check the enable Modbus checkbox on the device configuration settings. Both Modbus RTU (serial) and TCP are supported. Peripherals are hardware dependent. You can add whatever you want as long as you write the driver for it in the HAL layer. As for RS485, again, that’s platform dependent. OpenPLC abstracts from hardware, so it makes no difference for the software layer if you’re using RS485 or not.
Reply 0 0
Reply