Forking https://os.mbed.com/users/cam/code/Modbus/ to work for NUCLEO 64 boards
Fork of Cam's original FreeModbus port (https://os.mbed.com/users/cam/code/Modbus/)
Change: - Serial implementation to work for NUCLEO 64 boards and receive interrupts instead of timer. (see `portserial.cpp`)
Added: - Custom RTU mode. Allows for external implementation of packet receiving and sending. Sends and receives packets as whole frames (address + PDU) (i.e. this was added for a custom LoRa implementation). implement `xMBRTUCustGetPDU` and `xMBRTUCustSendResponse` (see `mbport.h`) and call `eMBRTUCustomInit( address )`. implementations need to be fully initialised as `eMBRTUCustomInit` only sets the address and nothing else.
Diff: mb.h
- Revision:
- 3:4cda95d7b6c5
- Parent:
- 0:0453a0a7e500
--- a/mb.h Tue Dec 03 09:13:22 2019 +0000 +++ b/mb.h Mon Jan 06 01:17:26 2020 +0000 @@ -85,6 +85,7 @@ typedef enum { MB_RTU, /*!< RTU transmission mode. */ + MB_RTU_CUSTOM, /*!< RTU block mode. not serial/sequential. */ MB_ASCII, /*!< ASCII transmission mode. */ MB_TCP /*!< TCP mode. */ } eMBMode; @@ -152,6 +153,29 @@ UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity ); /*! \ingroup modbus + * \brief Initialize the Modbus protocol stack for Modbus RTU in block/ + * full frame mode. + * + * This functions initializes the custom RTU module so any external + * communication method can be implemented (i.e. wireless protocols). + * Hardware should be initialised before as this does not call a init function + * like the others. + * Pleasecnote that the receiver is still disabled and no Modbus frames are + * processed until eMBEnable( ) has been called. + * + * \param ucSlaveAddress The slave address. Only frames sent to this + * address or to the broadcast address are processed. + * + * \return If the protocol stack has been initialized correctly the function + * returns eMBErrorCode::MB_ENOERR. Otherwise one of the following error + * codes is returned: + * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid + * slave addresses are in the range 1 - 247. + * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error. + */ +eMBErrorCode eMBRTUCustomInit( UCHAR ucSlaveAddress ); + +/*! \ingroup modbus * \brief Initialize the Modbus protocol stack for Modbus TCP. * * This function initializes the Modbus TCP Module. Please note that @@ -414,4 +438,4 @@ #ifdef __cplusplus PR_END_EXTERN_C #endif -#endif +#endif \ No newline at end of file