This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Modbus MSP430 communication strange response

Other Parts Discussed in Thread: MSP430F2274, MSP430F2618

I have connected a Modbus slave device to my MSP430F2274 , I am using the UART module. If I connect the slave to my PC and a Master device simulator, it works fine, and then I connect the slave to the MSP430 and it works fine to. The problem is if I turn down the slave and then I don´t connect the slave to the pc before connecting it to the MSP. In this case the the first byte of the response I receive from a request is not the slave address and it is in the second byte, the rest of the message seems to be ok but the last byte is missing. So I don´t really understand what is happening there. I have a baudrate of 19200 but since it works fine after using the Master simulator i think is not a problem of the uart configuration, maybe synchronization  of the slave, but I don´t know how it is done.

Thank you in advance.

  • I managed to fix it it was a software issue.

  • hi jamie,

     i am trying to implement MODBUS communication for my MSP430F2618 controller.Do you have any sample code for this application.

  • You should be a bit more specific about what you need, but the thing is that my application is a bit complicated, cause the MSP430 only cares about the communication between the meter, and the application that really implements the modbus is in my pc running in java, so I can give you the part of the MSP430 but I am not sure If would help you. Mostly it is the UART communication trough RS232 with the meter.

    Jaime

  •                              Actually i just want to act my MSP430F2618  controller as a slave. and MODICAN32 as a master . i just want to do communication via  modbus. so it should able to transmit 10 registers as well it should allow to receive minimum 10 registers values.

  • Hi I really don´t have the implementation of a modbus slave because is the part that my meter is. I give you an example of the modbus rtu crc calculation that must be useful for you. For me its working:

    public static int ModRTU_CRC(int[] buf, int len)
          {
            int crc = 0xFFFF;
            
            for (int pos = 0; pos <len; pos++) {
              crc ^= buf[pos];          // XOR byte into least sig. byte of crc
              //crc >>= 1;
              for (int i = 8; i != 0; i--) {    // Loop over each bit
                if ((crc & 0x0001) != 0) {      // If the LSB is set
                  crc >>= 1;                    // Shift right and XOR 0xA001
                  crc ^= 0xA001;
                }
                else                            // Else LSB is not set
                  crc >>= 1;                    // Just shift right
              }
            }
            
            // Note, this number has low and high bytes swapped, so use it accordingly (or swap bytes)
            int crcl = (crc & 0xFF00)/256; //Swaping  the bytes
            int crch = (crc & 0x00FF)*256;
            crc = crch + crcl;
            return crc;  
          }

    Its in java but you only have to change the int[] buf -> a pointer to the array you want to make the CRC and int len -> the length of the array. If you need help about the UART configuration maybe I can help you to but about the slave implementation you must google to search for it. I saw something when I start searching for my application but I did not use it.

**Attention** This is a public forum