Modbus in nRF52832. How can I implement this as I could find no relevant examples.

I am trying to control the 485 relay using the 485 to ttl converter. I implemented it on arduino using the following code:

#include<SoftwareSerial.h>

#define SoftSerial_RX     10
#define SoftSerial_TX     11

SoftwareSerial RS485Serial (SoftSerial_RX, SoftSerial_TX);

byte DeviceID = 0x01;

// ON/OFF Relay
/*                   {1:deviceId,
                      2:"Write Single Coil" function,
                      3,4: coil address,
                      5,6: output value,
                      7,8: Cyclic Redundancy Check for error detection}*/
byte ON_RELAY1[8]  = {DeviceID, 0x05, 0x00, 0x00, 0xFF, 0x00, 0x8C, 0x3A};
byte OFF_RELAY1[8] = {DeviceID, 0x05, 0x00, 0x00, 0x00, 0x00, 0xCD, 0xCA};
byte ON_RELAY2[8]  = {DeviceID, 0x05, 0x00, 0x01, 0xFF, 0x00, 0xDD, 0xFA};
byte OFF_RELAY2[8] = {DeviceID, 0x05, 0x00, 0x01, 0x00, 0x00, 0x9C, 0x0A};
void setup() {
  Serial.begin(9600);
  RS485Serial.begin(9600);
  pinMode(4, OUTPUT);

}

void loop() {
  RS485Serial.write(ON_RELAY1, 8);
  digitalWrite(4, HIGH);
  delay(500);
  RS485Serial.write(ON_RELAY2, 8);
  delay(500);
  RS485Serial.write(OFF_RELAY1, 8);
  delay(500);
  RS485Serial.write(OFF_RELAY2, 8);
  delay(500);
}

Now, I want to implement the same using nRF52dk 52832. But I am not able to write the parallel code. Have any of you done anything similar?

Thanks in advance.
Parents Reply Children
No Data
Related