Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free.

I have Code for Mod bus Library as below. I have Gone through lots of forum. How to assign device ID, slave address, length using below library function:

#include <SimpleModbusSlave.h>
#define  LED 9  
enum 
{     

  ADC_VAL,     
  PWM_VAL,        
  HOLDING_REGS_SIZE // leave this one
};

unsigned int holdingRegs[HOLDING_REGS_SIZE]; 
void setup()
{
  modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);    
  pinMode(LED, OUTPUT);
}

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

I am getting Error has.

SimpleModbusSlaveArduino.cpp: In function 'void setup()':
SimpleModbusSlaveArduino:79: error: 'SERIAL_8N2' was not declared in this scope

Let me know how to resolve issue.

share|improve this question
    
Link to the library? –  Peter K Apr 1 '14 at 11:52
    
Its being already added, How to link library?? –  AMPS Apr 1 '14 at 12:08
    
Sorry, I wasn't clear - could you give us a link to the library you're using? It is difficult to diagnose your problem otherwise. –  Peter K Apr 1 '14 at 12:10
    
@AMPS Just FYI. There is now a stack dedicated to Arduino arduino.stackexchange.com –  Nick Alexeev Apr 1 '14 at 15:38

1 Answer 1

Open up SimpleModbusSlave.c. Check the format of modbus_configure() matches what you have.

Open up SimpleModbusSlave.h. Check the define for SERIAL_8N2 exists.

I'm guessing it should be

modbus_configure(9600, 1, 2, HOLDING_REGS_SIZE);

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.