Hai
Currently i am working on Modbus Commnuication Protocol.I am new with this communication.
My objective is my master(TM4C123GH6PGE) wants to read the data of the socomec energy meter (i.e slave)which is supported to modbus RTU.
For this i written the code based on www.Freemodbus.org .i.e
1)First i initialized the eMBInit function
initialize_eStatus =eMBInit( MB_RTU, 0x05, 0, 9600, MB_PAR_NONE );
eMBErrorCode
eMBInit( eMBMode eMode, char ucSlaveAddress, char ucPort, long ulBaudRate, eMBParity eParity )
{
eMBErrorCode eStatus = MB_ENOERR;
/* check preconditions */
if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
{
eStatus = MB_EINVAL;
}
else
{
ucMBAddress = ucSlaveAddress;
switch ( eMode )
{
#if MB_RTU_ENABLED > 0
case MB_RTU:
pvMBFrameStartCur = eMBRTUStart;
pvMBFrameStopCur = eMBRTUStop;
peMBFrameSendCur = eMBRTUSend;
peMBFrameReceiveCur = eMBRTUReceive;
pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBPortClose : NULL;
pxMBFrameCBByteReceived = xMBRTUReceiveFSM;
pxMBFrameCBTransmitterEmpty = xMBRTUTransmitFSM;
pxMBPortCBTimerExpired = xMBRTUTimerT35Expired;
eStatus = eMBRTUInit( eMode,ucMBAddress, ucPort, ulBaudRate, eParity );
break;
default:
eStatus = MB_EINVAL;
}
if( eStatus == MB_ENOERR )
{
if( !xMBPortEventInit( ) )
{
/* port dependent event module initalization failed. */
eStatus = MB_EPORTERR;
}
else
{
eMBCurrentMode = eMode;
eMBState = STATE_DISABLED;
}
}
}
return eStatus;
}
eMBErrorCode
eMBRTUInit(eMBMode eMode, char ucSlaveAddress, char ucPort, long ulBaudRate, eMBParity eParity )
{
eMBErrorCode eStatus = MB_ENOERR;
if( xMBPortSerialInit( ucPort,ulBaudRate,8, eParity ) != TRUE )
{
eStatus = MB_EPORTERR;
}
else
{
/* If baudrate > 19200 then we should use the fixed timer values
* t35 = 1750us. Otherwise t35 must be 3.5 times the character time.
*/
if( ulBaudRate > 19200 )
{
usTimerT35_50us = 35; /* 1800us. */
}
else
{
++countk;
/* The timer reload value for a character is given by:
*
* ChTimeValue = Ticks_per_1s / ( Baudrate / 11 )
* = 11 * Ticks_per_1s / Baudrate
* = 220000 / Baudrate
* The reload for t3.5 is 1.5 times this value and similary
* for t3.5.
*/
usTimerT35_50us = ( 7UL * 220000UL ) / ( 2UL * ulBaudRate );
}
if( xMBPortTimersInit( ( int) usTimerT35_50us ) == 1 )
// xMBPortTimersInit( ( short ) usTimerT35_50us );
{
eStatus = MB_EPORTERR;
}
}
//EXIT_CRITICAL_SECTION( );
return eStatus;
}
bool xMBPortSerialInit (char aa, long bb, char cc, eMBParity dd)
{
}
In this my doubt is what should i write in this function is it needed to send the port,baudrate,databits and parity? to the slave device?
I am confusing with this.please send me if any body done the implementation on modbus with TM4C controllers.
please help me and plese give me email i wil send the total project file ,what i written to know the mistakes what i have done
Thank u