Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the frame interval time setting #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions Modbus/Modbus/ModbusRTUMaster/MDM_RTU_Fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,16 @@ MDError MDM_RTU_Init(
/*Current real-time time unit 100US*/
pModbusRTU->timesTick=0;

T=(1.0/(float)baud)*10000;
uint16 time=0;
time=T*(dataBits+(parity?1:0));
if(stopBits==0){
time+=T;
}else if(stopBits==1){
time+=T*1.5f;
}else if(stopBits==2){
time+=T*2;
if(baud > 19200)
{
pModbusRTU->frameIntervalTime=17.5; //
}
else
{
uint16 bitnum = 1 + dataBits + stopBits; //��ʼλ+����λ+ֹͣλ
T=(1.0f/(float)baud)*10000*bitnum; //����1bit����Ҫ��ʱ�䣨��us��*һ���ַ���λ���� ������һ���ַ���ʱ��
pModbusRTU->frameIntervalTime=3.5f*T;/*This parameter needs to be set according to the baud rate*/
}
pModbusRTU->frameIntervalTime=time;/*This parameter needs to be set according to the baud rate*/

pModbusRTU->recvFlag=0;/*Receive flag*/
if(mdRTUSerialInitFun!=NULL){
Expand Down
2 changes: 1 addition & 1 deletion Modbus/Modbus/ModbusRTUMaster/MDM_RTU_Fun.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef struct{
uint32 timesTick;

/*Frame interval time 3.5T*/
uint16 frameIntervalTime;
float frameIntervalTime;

/*CRC16 received*/
uint16 CRC16Update;
Expand Down
19 changes: 9 additions & 10 deletions Modbus/Modbus/ModbusRTUSlave/MDS_RTU_Fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ void MDS_RTU_Init(PModbusS_RTU pModbusRTU,MD_RTU_SerialInit mdRTUSerialInitFun,u
pModbusRTU->lastSendTimes=0x00000000;
pModbusRTU->timesTick=0x00000000;

T=(1.0/(float)baud)*100000;// 100us
uint16 time=0;
time=T*(dataBits+(parity?1:0));
if(stopBits==0){
time+=T;
}else if(stopBits==1){
time+=T*1.5f;
}else if(stopBits==2){
time+=T*2;
if(baud > 19200)
{
pModbusRTU->frameIntervalTime=17.5; //
}
else
{
uint16 bitnum = 1 + dataBits + stopBits; //��ʼλ+����λ+ֹͣλ
T=(1.0f/(float)baud)*10000*bitnum; //����1bit����Ҫ��ʱ�䣨��us��*һ���ַ���λ���� ������һ���ַ���ʱ��
pModbusRTU->frameIntervalTime=3.5f*T;/*This parameter needs to be set according to the baud rate*/
}
pModbusRTU->frameIntervalTime=time;/*This parameter needs to be set according to the baud rate*/

pModbusRTU->CRC16Update=0xFFFF;

Expand Down
2 changes: 1 addition & 1 deletion Modbus/Modbus/ModbusRTUSlave/MDS_RTU_Fun.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct{
uint32 lastSendTimes;

/*Frame interval time 3.5T*/
uint16 frameIntervalTime;
float frameIntervalTime;

/*CRC16 received*/
uint16 CRC16Update;
Expand Down
Loading