#include "mbed.h"
#include "TextLCD.h"
Serial RS485(D1,D0); // Tx, Rx
DigitalOut ho(D2); // use this pin for able the RS485 trasmission
TextLCD lcd(D12, D11, D9, D8, D7, D6); // rs, e, d4-d7 --
int regvalue[9];
int main() {
lcd.printf("START\n");
RS485.baud(9600);
while(1) {
ho = 1; // hight output from digital out pin
RS485.putc(0x05); // slave add
RS485.putc(0x03); // function code
RS485.putc(0x00); // Hi PDU add
RS485.putc(0x13); // low PDU add
RS485.putc(0x00); // Hi N reg
RS485.putc(0x02); // Lo N reg
RS485.putc(0x34); // Hi CRC
RS485.putc(0x4A); // Lo CRC
wait_ms(200); // Silent interval
ho = 0; // low output from digital out pin
for (int count = 0; count < 8; count++) {
regvalue[count] = RS485.getc(); // Retrieving received register from modbus
lcd.printf(regvalue[count]);
}
lcd.printf("OK\n");
wait_ms(1000);
}
}