@@ -168,7 +168,7 @@ class Modbus
168168 uint16_t *au16regs;
169169 uint16_t u16InCnt, u16OutCnt, u16errCnt;
170170 uint16_t u16timeOut;
171- uint32_t u32time, u32timeOut;
171+ uint32_t u32time, u32timeOut, u32overTime ;
172172 uint8_t u8regsize;
173173
174174 void init (uint8_t u8id, uint8_t u8serno, uint8_t u8txenpin);
@@ -195,7 +195,7 @@ class Modbus
195195 Modbus (uint8_t u8id);
196196 void begin (long u32speed);
197197 void begin (SoftwareSerial *sPort , long u32speed);
198- void begin (long u32speed, uint8_t u8config);
198+ // void begin(long u32speed, uint8_t u8config);
199199 void begin ();
200200 void setTimeOut ( uint16_t u16timeout); // !<write communication watch-dog timer
201201 uint16_t getTimeOut (); // !<get communication watch-dog timer value
@@ -210,6 +210,7 @@ class Modbus
210210 uint8_t getState ();
211211 uint8_t getLastError (); // !<get last error message
212212 void setID ( uint8_t u8id ); // !<write new ID for the slave
213+ void setTxendPinOverTime ( uint32_t u32overTime );
213214 void end (); // !<finish any communication and release serial communication port
214215};
215216
@@ -373,7 +374,7 @@ void Modbus::begin(SoftwareSerial *sPort, long u32speed)
373374 * @param config data frame settings (data length, parity and stop bits)
374375 * @ingroup setup
375376 */
376- void Modbus::begin (long u32speed,uint8_t u8config)
377+ /* void Modbus::begin(long u32speed,uint8_t u8config)
377378{
378379
379380 switch( u8serno )
@@ -412,7 +413,7 @@ void Modbus::begin(long u32speed,uint8_t u8config)
412413 while(port->read() >= 0);
413414 u8lastRec = u8BufferSize = 0;
414415 u16InCnt = u16OutCnt = u16errCnt = 0;
415- }
416+ } */
416417
417418/* *
418419 * @brief
@@ -444,6 +445,21 @@ void Modbus::setID( uint8_t u8id)
444445 }
445446}
446447
448+ /* *
449+ * @brief
450+ * Method to write the overtime count for txend pin.
451+ * It waits until count reaches 0 after the transfer is done.
452+ * With this, you can extend the time between txempty and
453+ * the falling edge if needed.
454+ *
455+ * @param uint32_t overtime count for txend pin
456+ * @ingroup setup
457+ */
458+ void Modbus::setTxendPinOverTime ( uint32_t u32overTime )
459+ {
460+ this ->u32overTime = u32overTime;
461+ }
462+
447463/* *
448464 * @brief
449465 * Method to read current slave ID address
@@ -825,6 +841,7 @@ void Modbus::init(uint8_t u8id, uint8_t u8serno, uint8_t u8txenpin)
825841 this ->u8serno = u8serno;
826842 this ->u8txenpin = u8txenpin;
827843 this ->u16timeOut = 1000 ;
844+ this ->u32overTime = 0 ;
828845}
829846
830847void Modbus::init (uint8_t u8id)
@@ -833,6 +850,7 @@ void Modbus::init(uint8_t u8id)
833850 this ->u8serno = 4 ;
834851 this ->u8txenpin = 0 ;
835852 this ->u16timeOut = 1000 ;
853+ this ->u32overTime = 0 ;
836854}
837855
838856/* *
@@ -917,6 +935,8 @@ void Modbus::sendTxBuffer()
917935 if (u8serno < 4 )
918936 port->flush ();
919937 // return RS485 transceiver to receive mode
938+ volatile uint32_t u32overTimeCountDown = u32overTime;
939+ while ( u32overTimeCountDown-- > 0 );
920940 digitalWrite ( u8txenpin, LOW );
921941 }
922942 if (u8serno<4 )
0 commit comments