zenniz
Junior Member level 3
- Joined
- Mar 25, 2013
- Messages
- 29
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Singapore
- Activity points
- 1,497
I'm trying to communicate with the energy meter (MODBUS protocol) using mbed microcontroller via SIPEX SP485CS chip.
I'm unable to receive any data from the energy meter. I can confirm that all my hardware is working correctly as i have extra for each component.
I'm not sure if is the connection or the program's problem. The program will stop after the printf("Getting data\n");. I'm always getting a 3.3V reading from Tx pin28 while 0V reading from Rx pin27, is this normal?
I'm unable to receive any data from the energy meter. I can confirm that all my hardware is working correctly as i have extra for each component.
I'm not sure if is the connection or the program's problem. The program will stop after the printf("Getting data\n");. I'm always getting a 3.3V reading from Tx pin28 while 0V reading from Rx pin27, is this normal?
Code:
[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]