Go Down

Topic: ModBus Update (Read 79 times) previous topic - next topic

LennReebergen

Hello,

I have a question about the program SimpleModbusSlave_DUE that I have added.

The    modbus_update();   givens delays of approximately 14 MSec

I'm looking for program code that the main program continues during the   modbus_update()  delays.

Or a tip so that I can solve the problem.

Thanks in advance.

Lenn

===========================================================

#include <SimpleModbusSlave_DUE.h>

#define  LED_Modbus 9 

//////////////// registers of your slave ///////////////////
enum
{     
  // just add or remove registers and your good to go...
  // The first register starts at address 0
  ADC_VAL,     
  PWM_VAL,       
  HOLDING_REGS_SIZE // leave this one
  // total number of registers for function 3 and 16 share the same register array
  // i.e. the same address space
};

unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array
////////////////////////////////////////////////////////////

void setup()
{
 
   modbus_configure(&Serial, 9600, SERIAL_8N2, 2, HOLDING_REGS_SIZE, holdingRegs);

  // modbus_update_comms(baud, id) is not needed but allows for easy update of the
  // port variables and slave id dynamically in any function.
   modbus_update_comms(9600, 1);
 
//   pinMode(LED_Modbus, OUTPUT);


}

void loop()
{


   modbus_update();
 

 
  holdingRegs[ADC_VAL] = analogRead(A0); // update data to be read by the master to adjust the PWM
 
   analogWrite(LED_Modbus, holdingRegs[PWM_VAL]>>2); // constrain adc value from the arduino master to 255
}

Go Up