Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <ModbusMaster.h>
- #define RX_PIN 2
- #define TX_PIN 3
- #define CURRENT_SLAVE_ID 2 // Now communicating with ID 2
- #define CURRENT_BAUD_RATE 4800
- #define RENKE_REG_BAUD 0x07D1 // Baud rate EEPROM register
- #define BAUD_CODE_9600 2 // 0=2400, 1=4800, 2=9600
- SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
- ModbusMaster node;
- void setup()
- {
- Serial.begin(9600);
- while (!Serial);
- delay(1000);
- Serial.println("Renke Baud Rate Updater (Targeting ID 2)");
- Serial.println("----------------------------------------");
- modbusSerial.begin(CURRENT_BAUD_RATE);
- node.begin(CURRENT_SLAVE_ID, modbusSerial);
- delay(500);
- Serial.print("Writing Baud 9600 (Value: 2) to register 0x07D1... ");
- uint8_t result = node.writeSingleRegister(RENKE_REG_BAUD, BAUD_CODE_9600);
- if (result == node.ku8MBSuccess) {
- Serial.println("SUCCESS!");
- } else {
- // If the sensor switches its UART speed immediately, a timeout response is expected
- Serial.print("Response Code: 0x");
- Serial.print(result, HEX);
- Serial.println(" (Timeout is normal if UART switched instantly)");
- }
- Serial.println("----------------------------------------");
- Serial.println("Power cycle the 12V supply to finalize the 9600 baud setting.");
- }
- void loop() {}
Advertisement
Add Comment
Please, Sign In to add comment