(Not Working ) Nucleo F767ZI communication Modbus RS 485 Using Max 485 Module

Hi i am New for Arm mbed ,MY project is i want to Control 3 phase induction motor speed using VFD
Here my inovance VFD controlling by (RS 485 Communication Using Max 485 Module) STM 32 Nucleo F767ZI controller,

My slave ID -01,
Baud rate -9600.
modbus data format -8-N-2,

All my VFD Setting was done and Cross checked by USB to RS 485 Driver using modbuspoll Software.(Here i controlling Motor Speed and Direction)

my connection max 485 drive
Nucleo PD_6 (RX)->RO
RE and DE short connect Digital pin PC_8
Nucleo PD_5 (Tx)->DI

VCC connect 5V power supply
A connect VFD 485+
B connect VFD 485-
Gnd connect with GND

this photo is MY VFD Setting

Below i Attached my code


#include "mbed.h" 
#include "BufferedSerial.h"

Serial pc(USBTX, USBRX,115200); 
Serial RS485(PD_5,PD_6); // Tx, Rx
DigitalOut ho(PC_8);
//Serial RS485(PD_6,PD_5);

typedef uint8_t byte;

//byte data[9] = {0x01,0x04,0x00,0x48,0x00,0x02,0xf1,0xdd};//your data
byte enable[9] = {0x01,0x03,0x04,0x00,0x00,0x00,0X01,0x3B,0xF3};
//byte enable[9] = {0x01,0x06,0x20,0x0E,0x00,0x08,0xE2,0x0F};//your data
//byte run[9] = {0x01,0x06,0x20,0x89,0x00,0x0A,0xD3,0xE7};//your data
byte run[9] = {0x01,0x06,0x04,0x10,0x00,0x50,0x00,0X80,0xCA};//your data
//byte stop[9] = {0x01,0x06,0x20,0x0E,0x00,0x07,0xA2,0x0B};//your data
 
int main()
{
    printf("Main\n");
    RS485.baud(9600);
    pc.baud(115200);
    while(1) {
       // RS485.baud(115200);
        pc.printf("Starting\n");
        ho = 1;                  // 3.3V output from digital out pin
        
        for (int i=0; i<(sizeof(enable)-1);i++)
        {
            RS485.putc(enable[i]);    
        }

        wait_ms(2000);         // Silent interval
        printf("\n Enable done");
        for (int i=0; i<(sizeof(run)-1);i++)
        {
            RS485.putc(run[i]);    
        }
        printf(" \n Run Done waiting for 5 min");
        wait_ms(5000);         // Silent interval
        
      /*  for (int i=0; i<(sizeof(stop)-1);i++)
        {
            RS485.putc(stop[i]);    
        }

        wait_ms(50);         // Silent interval*/
        
        pc.printf("Getting data\n");
        
        ho = 0;
        pc.printf("The RS485 value %d\n",RS485.readable());
        
        char buffer[50];
        RS485.gets(buffer, 9);
        
        for (int count = 0; count < 8; count++) {
            pc.printf("%02hhX", buffer[count]);
        }
        pc.printf("\n");
        pc.printf("Done\n");
        wait_ms(1000);
    }
} 

in some known this please help me to complete my project.

Blockquote

JohnnyKJan Kamidra

Please help this issue i want finish my projects.

Hello,

sorry, but what does mean “not working”? What it does and what does not? What is the expected result?

        printf(" \n Run Done waiting for 5 min");
        wait_ms(5000);         // Silent interval

that is definitely not 5 min but 5 sec

BR, Jan

hi johnny jan kamidra

i corrected this one

printf(" \n Run Done waiting for 5 min");
        wait(300);         // Silent interval

MY project is i want to Control 3 phase induction motor speed and direction using VFD
Here my inovance VFD controlling by (RS 485 Communication Using Max 485 Module) STM 32 Nucleo F767ZI controller UART2,

My slave ID -01,
Baud rate -9600.
modbus data format -8-N-2,

All my VFD Setting was done and Cross checked by USB to RS 485 Driver using modbuspoll Software.(Here i controlling Motor Speed and Direction)

my connection max 485 drive
Nucleo PD_6 (RX)->RO
RE and DE short connect Digital pin PC_8
Nucleo PD_5 (Tx)->DI

VCC connect 5V power supply
A connect VFD 485+
B connect VFD 485-
Gnd connect with GND

this photo is MY VFD Setting

Below i Attached my code

#include "mbed.h" 
#include "BufferedSerial.h"

Serial pc(USBTX, USBRX,115200); 
Serial RS485(PD_5,PD_6); // Tx, Rx
DigitalOut ho(PC_8);
//Serial RS485(PD_6,PD_5);

typedef uint8_t byte;

//byte data[9] = {0x01,0x04,0x00,0x48,0x00,0x02,0xf1,0xdd};//your data
byte enable[9] = {0x01,0x03,0x04,0x00,0x00,0x00,0X01,0x3B,0xF3};
//byte enable[9] = {0x01,0x06,0x20,0x0E,0x00,0x08,0xE2,0x0F};//your data
//byte run[9] = {0x01,0x06,0x20,0x89,0x00,0x0A,0xD3,0xE7};//your data
byte run[9] = {0x01,0x06,0x04,0x10,0x00,0x50,0x00,0X80,0xCA};//your data
//byte stop[9] = {0x01,0x06,0x20,0x0E,0x00,0x07,0xA2,0x0B};//your data
 
int main()
{
    printf("Main\n");
    RS485.baud(9600);
    pc.baud(115200);
    while(1) {
       // RS485.baud(115200);
        pc.printf("Starting\n");
        ho = 1;                  // 3.3V output from digital out pin
        
        for (int i=0; i<(sizeof(enable)-1);i++)
        {
            RS485.putc(enable[i]);    
        }

        wait_ms(2000);         // Silent interval
        printf("\n Enable done");
        for (int i=0; i<(sizeof(run)-1);i++)
        {
            RS485.putc(run[i]);    
        }
        printf(" \n Run Done waiting for 5 min");
        wait(300);         // Silent interval
        
      /*  for (int i=0; i<(sizeof(stop)-1);i++)
        {
            RS485.putc(stop[i]);    
        }

        wait_ms(50);         // Silent interval*/
        
        pc.printf("Getting data\n");
        
        ho = 0;
        pc.printf("The RS485 value %d\n",RS485.readable());
        
        char buffer[50];
        RS485.gets(buffer, 9);
        
        for (int count = 0; count < 8; count++) {
            pc.printf("%02hhX", buffer[count]);
        }
        pc.printf("\n");
        pc.printf("Done\n");
        wait_ms(1000);
    }
} 

in some known this please help me to complete my project.

Blockquote

Ok, that is copy&paste from above so nothing new and this does not tell me antything about the real state.

I am not sure what this exactly mean, but I suppose you used USB to RS 485 bridge and send commands directly from PC to VFD and was working, right?
If yes then would be cool to make a comparsion between how it looks with Mbed device and how with the USB to RS 485 bridge.

BR, Jan

I am not sure what this exactly mean, but I suppose you used USB to RS 485 bridge and send commands directly from PC to VFD and was working, right??

yes working fine

do you have any references code for 485 communication …

Nope, but you can try this library - RS485 - A basic library for RS485 communication | Mbed

BR, Jan

Any progress?

i tried johnny its not working,

but it was work arduino uno r3 i controlled motor speed and direction.

i am keep on trying with stm 32 nucleo board ,
if you have the time can you share any RS 485 sample code (working one).
thanks.

I do not use RS485 for anything so I do not have any verified example code.
How I wrote you have working part with USB to RS485 bridge and not working Mbed device. So most easy part should be to connect Mbed device to VFD and listen also with USB to RS485 bridge and look how is data from Mbed are present in Console over the bridge and check if are in expected format.

BR, Jan

ok i will check and update .

Hi Fermidicus,

From your code i am missing the control over the Read Enable and Write Enable pins of your module. RS-485 is half duplex, this means send OR receive.

Quote " There are a few types of MAX485 modules available in the market. One of them is a basic MAX485 circuit board with input and output pins for direct interfacing. In addition to the TX and RX signals, you also need to control the RE and DE pins."

Next to this, Modbus uses an 16 bit CRC, without the CRC the used VFD will not do anyhting. The suggested modbus library takes care of this,

I might suggest to put some sort of a serial spy in between the serial lines of your MAX485 (just a serial to usb converter will do). You can add your MAX485 module to the existing RS-485 bus between your VFD and RS485-USB device and look at the real data being sent over de rs-485 bus.

thanks
i done the sending data to VFD and its Running Fine.
now i trying to Read the Data From VFD using Modbus.