Thread: Weird issue with energy meter using modscan

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    4

    Weird issue with energy meter using modscan

    I'm using an mbed micro-controller to retrieve register from Integra 1630 energy meter with modbus via a SIPEX SP485CS chip (RS485 level shiftier).
    All the component and connection are working correctly.(Double checked) Using the same program with different reigster, i'm able to get good modbus reply from other type of energy meter with modbus.
    I always a register of 0x00 instead of good modbus reply. Why am i always getting 0x00???

    Code:
    #include "mbed.h"
    
    
    Serial RS485(p28,p27);
    DigitalOut ho(p26);
    
    
    int regvalue[9];
    
    
    int main()
    {
        ho = 0;
        while(1) {
            RS485.baud(9600);
            printf("Starting\n");
            ho = 1;
            RS485.putc(0x01);   // slave
            RS485.putc(0x04);   // function code
            RS485.putc(0x00);   // Hi add
            RS485.putc(0x48);   // low add
            RS485.putc(0x00);   // Hi N reg 
            RS485.putc(0x02);   // Lo N reg
            RS485.putc(0xf1);   // Hi CRC
            RS485.putc(0xdd);   // Lo CRC
            wait(0.2);          // Silent interval
            printf("Getting data\n");
            ho = 0;
            for (int count = 0; count < 8; count++) {
                regvalue[count] = RS485.getc();
                printf("%X - ", regvalue[count]);
            }
            wait(1);
        }
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It's hard to give a specific answer, as you haven't provided useful information. Plus, this is not actually a C programming problem. It is specific to the hardware you're using, so you'd be better off seeking support from people who know about the particular items you're working with.

    I'd bet, contrary to your double checking, that you have a wiring problem, such as microcontroller output going to an output pin rather than to an input pin on the meter.

    If you're adamant the wiring is okay, look at the board schematics and specifications for both the meter giving your problem and of the "other type" that is working. In particular, look at specifications of required currents and voltages, and check they're all within required ranges.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Mmm -> Modbus communication problems when using other RS485 chip

    Some questions
    1. Why are you setting the baud rate each time around the loop?

    2. How long is wait(0.2); ?
    Is the interface to wait really floating point? If it isn't, you just got zero.

    3. ho = 1;
    Directly toggling hardware lines, which in turn control bits of actual hardware might involve a certain amount of "settle" time before it is ready.
    You're just setting this and immediately blasting chars out over the link.

    Do you have to worry about CTS / RTS issues with your getc / putc methods?

    Do you have to worry about serialisation time (the time it takes to clock 1 char off the wire) with your interface?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird realloc issue
    By jtay in forum C Programming
    Replies: 8
    Last Post: 06-30-2011, 10:42 AM
  2. Some weird issue.
    By dbzx in forum C Programming
    Replies: 7
    Last Post: 04-12-2009, 04:10 PM
  3. weird pointer issue
    By Chaplin27 in forum C++ Programming
    Replies: 5
    Last Post: 08-01-2006, 09:20 AM
  4. Weird gethostbyname() issue
    By Xterria in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-26-2006, 09:44 PM
  5. HTTP traffic meter
    By Carlos in forum Windows Programming
    Replies: 3
    Last Post: 10-02-2003, 04:27 PM