Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RS485 with mbed microcontroller. Not receiving any data

Status
Not open for further replies.

zenniz

Junior Member level 3
Junior Member level 3
Joined
Mar 25, 2013
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Singapore
Visit site
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?

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]

123.png
 

Check on oscilloscope what are you getting from pin A or B.
In your schematic it'll be better to use pull up and pull down at A & Bwhile using 485 conversion...
wikipage of RS485 has details explanation about how to connect them and why we need them and which values we should use for pull up & pull down.

Because it seems that your slave may not be getting any thing from controller.
Check the slave input pin also (using breakpoint at any of putc function) on oscilloscope. You will be clear whether the slave is getting any thing or not.
Once it get something then only you can aspect to have data from slave.
 

@Jigar
Thank you, i misinterpreted the A and B pin the other way round. I added the pull up/down resistor.

I encountered another problem. I have two slave connected to master. The first slave is working correctly. The second slave stop responding after several poll. What happen?
The connection are daisy chained, all slave and master are no more than 10m away from each other.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top