10 years, 6 months ago.

RS485 with st Nucleo, not sand any data

hi to all

I'm trying to communicate with the energy meter (MODBUS protocol) using st nucelo F401RE via MAXIM MAX485 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. I using Arduino uno rev.3 for try it. I use a oscilloscope but i don't see nothing, i think the problem is the serial comunication, can you help me?

this in my code:

#include "mbed.h"
#include "TextLCD.h"

Serial RS485(D1,D0); // Tx, Rx
DigitalOut ho(D2); // use this pin for able the RS485 trasmission
TextLCD lcd(D12, D11, D9, D8, D7, D6); // rs, e, d4-d7  --
int regvalue[9];

int main() {
     lcd.printf("START\n");    
  RS485.baud(9600);
    while(1) {

        ho = 1;                  // hight output from digital out pin
        RS485.putc(0x05);   // slave add
        RS485.putc(0x03);   // function code
        RS485.putc(0x00);   // Hi PDU add
        RS485.putc(0x13);   // low PDU add
        RS485.putc(0x00);   // Hi N reg 
        RS485.putc(0x02);   // Lo N reg
        RS485.putc(0x34);   // Hi CRC
        RS485.putc(0x4A);   // Lo CRC
        wait_ms(200);         // Silent interval
        ho = 0;                  // low output from digital out pin
        for (int count = 0; count < 8; count++) {
            regvalue[count] = RS485.getc(); // Retrieving received register from modbus
         lcd.printf("%X - ",regvalue[count]);
        }
    lcd.printf("OK\n");     
        wait_ms(1000); 
    
 }
   
}

best regards A.

2 Answers

10 years, 6 months ago.

Hi Antonio, I found the same problem on NUCLEO-F152RE. For use the USART2 on D0 and D1, is necessary: remove SB13 and SB14 and put SB62 and SB62. See here: http://www.emcu.it/NUCLEOevaBoards/U2andL152/U2andL152.html#USART2_for_communication_with_shield_or If you do this change, you lost the Virtual COM via USB.

10 years, 6 months ago.

D0/D1 are normally disabled since they are used for the serial connection to the host PC via USB. You should select another serial port instead or modify the nucleo hardware (see manual).

tahnks for you answer but don't work, my code is

#include "mbed.h"
Serial pc(SERIAL_TX, SERIAL_RX); // sarebbero d1 e do
Serial RS485(D8,D2); // Tx, Rx
DigitalOut ho(D9); // use this pin for able the trasmission
int regvalue[8];

int main() {

pc.printf("START\n"); 
  RS485.baud(9600);
    while(1) {
pc.printf("START2\n"); 
        
        ho = 1;                  // hight output from digital out pin
        RS485.putc(0x05);   // slave add
        RS485.putc(0x03);   // function code
        RS485.putc(0x00);   // Hi PDU add
       RS485.putc(0x13);   // low PDU add
        RS485.putc(0x00);   // Hi N reg 
        RS485.putc(0x02);   // Lo N reg
        RS485.putc(0x34);   // Hi CRC
        RS485.putc(0x4A);   // Lo CRC
        wait_ms(200);         // Silent interval
        ho = 0;                  // low output from digital out pin
        for (int count = 0; count < 8; count++) {
            regvalue[count] = RS485.getc(); // Retrieving received register from modbus
         pc.printf("%X - ",regvalue[count]);
        
        
       }
    pc.printf("END\n");     
        wait_ms(1000); 
    
 }  
}


I don't see nothing, can you help me?

posted by Antoniolinux B. 08 May 2014

There seems to be a problem with UART1 on D8/D2 or PA_9/PA_10. This should be reported as a bug. A quick workaround is to use UART6 on PA_11/PA12. That works on my F401. Try:

//Serial RS485(D8,D2); // Tx1, Rx1 - not working
//Serial RS485( PA_9,PA_10); // Tx1, Rx1 - not working
Serial RS485(PA_11,PA_12); // Tx6, Rx6 - OK

Also make sure you have updated the mbed lib to the latest version (right click on the lib in your project).

posted by Wim Huiskamp 09 May 2014

thanks for your answare but don't work, i write this: <<code>> Serial RS485(PA_11,PA_12); DigitalOut ho(PC_6); <<\code>> but i think i have a problem with PC_6, when i use osscilloscope i see don't active rs485 comunication, do you have a idea can i fix it? best regards

posted by Antoniolinux B. 10 May 2014

This code definitely works for the serial port (at least for the latest mbed lib version)

Serial RS485(PA_11,PA_12); 
DigitalOut ho(D9); 

I have tested the transmission directly on the PA_11 pin with a logic analyser. However, you will see that transmitted message only once since it then waits forever for a reply (getc) which may not happen in case something is wrong with the energymeter. A scope will not show this single message unless it has a digital memory.

You can test it by commenting out the receive part

for (int count = 0; count < 8; count++) {
   regvalue[count] = RS485.getc(); // Retrieving received register from modbus
   pc.printf("%X - ",regvalue[count]);
}

Maybe try another pin instead of PC_6. That pin also has a secondary function as TX6. Maybe there are some more bugs in the F401 pin library that have not been found.

posted by Wim Huiskamp 10 May 2014