[SIZE=2]#include "mbed.h"
Serial RS485(p28,p27); // Tx, Rx
DigitalOut ho(p26);
int regvalue[9];
int main()
{
printf("Starting\n");
RS485.baud(9600);
while(1) {
RS485.baud(9600);
printf("Starting\n");
ho = 1; // 3.3V output from digital out pin
RS485.putc(0x01); // slave add
RS485.putc(0x04); // function code
RS485.putc(0x00); // Hi PDU add
RS485.putc(0x48); // low PDU add
RS485.putc(0x00); // Hi N reg
RS485.putc(0x02); // Lo N reg
RS485.putc(0xf1); // Hi CRC
RS485.putc(0xdd); // Lo CRC
wait_ms(200); // Silent interval
printf("Getting data\n");
ho = 0; // 0V output from digital out pin
for (int count = 0; count < 8; count++) {
regvalue[count] = RS485.getc(); // Retrieving received register from modbus
printf("%X - ", regvalue[count]);
}
printf("Done\n");
wait_ms(1000);
}
} [/SIZE]