Today is...
Tuesday, January 17, 2017
Welcome to, the global online
community of automation professionals.
Featured Video...
Featured Video
A demonstration of EtherCAT control of linear motors using the CTC EtherCAT master.
Our Advertisers
Help keep our servers running...
Patronize our advertisers!
Visit our Post Archive
Modbus C or assembler source code for microcontroller
I am working actually with protocol modbus and microcontroller AT89c52.
By Marcos Torres on 4 September, 2003 - 11:38 pm

I am working actually with protocol modbus and microcontroller AT89c52. I would like to communicate this microcontroller through protocol modbus but I need to create the protocol with language c or assembler. I would appreciate if someboby send me it. thanks.

Marcos Enrique

I assume you have looked at the best general location,

Also, if you do not absolutly require C then have you looked at the BASIC cross compiler for the ATMEL 8952, BASCOM BASIC. You can locate that here

They have a MODBUS library that works with the BASIC cross compiler. There may be more available for the AVR than the 8052 series chips.


I'm also working in a communication between one microprocesseur and one automate by modbus rtu protocol. I have been developping software in C but on CCS interface. I can receive and transmit trame. For the moment I'm looking for some piece of information about function treated in Modbus protocole but I can't find it.
My software run without problem but I need to add this part to decode the function send and principally about the different counter.

In other and, I try it with a system to command and I can transmit without problem an adress card, a function wich isn't decode for the moment, until 252 data byte, and calculate the crc code.

If you are interrested please notify me in my email and I will send you the soft If you can help me about the function.

PS my email:

I am working on ABB PLC I want to get the values stored in PLCs Holding registers. Can Someone tell me how to give 3.5 Character times in the start of the frame and end of the frame? Even I dont understand how to trigger my frame to the PLC. Please help me out of this problem.

You can calculate 3.5 character time easily.

in RTU mode we have 11 bits/character
let baud rate = 9600 then

1 character time = 11 * 1/9600
= 1145.83 uSec OR
= 1146 mSec

3.5 Character time = 4446*3.5 = 4 mSec (appx)

Hope i answered the question

Engr. Amir Rashid Chishti

By Vu Hong Quan on 30 November, 2003 - 12:51 pm


As my understand, MODBUS protocol use 64kB address space, with microprocessor it's problem. I don't know how to map address space.

I usual development my aplication base on OMRON host link protocol with MP 89Cxx serial, it is work well.

Could any body exchange with me some experiences about development standard protocol in MP 89Cxx, please feel free contact me via my email.


Vu Hong Quan
email :

hai Marcos

I am at the same stage at where u r.Now i have been searching the same.if u have got any information please reply me at

By Marcelo Calcia on 5 February, 2004 - 12:13 am

Hello Marcos... Now Im trying to communicate a PIC microcontroller with a speed variator ATV28 Telemecanique. I have read some archives about that, but now I have to make the routines for the MODBUS protocol and the CRC cyclical redundancy checking. I appreciate if you can help me with this job. Besides I can give you the information obtained in the future.


hi to all,

i also working on modbus protocol.
can u pls send me sample code of it?
e-mail id:


I am working on modbus protocol using TI 2812. Can anyone send me some sample codes in C? Thanks.
lp_zheng @

By Mohammad Arshad on 9 June, 2004 - 1:31 am


This is arshad. Marcos u simply need to follow the format of modbus. This format u can freely download from net. I have implemented it using assembly language, i will send it u.

By attilio drei on 11 June, 2004 - 1:37 am

hi, anyone have implemented modbus serial for picmicro in assembler?

if yes please contact me


Can u send it to me as well? I need to implement it in Ansi C for a RS232 Port.




Dear All:

I'm also looking for Modbus/RTU C source code for 8051, anyone can give me ref. code, thanks!

Best regards.
PS. my mail :

Hi, Arshad,
This is Maharudra.
Can you send me the assembly language implementation?

send detail requirement

By ozge bostan on 1 October, 2004 - 5:48 pm


i am a new graduated engineer and i am workin on assembly language implementation of modbus too..

may i take a look at your source code?
could you send it to me?

my address is:

Dear sir,

Can U guide me how I can make a device having modbus rtu communication using 8051 microcontroller programming language? Plz write me your ans. Any good site or documents are invited.

Ankit Rana

Hi Arshad!

I am trying to implement modbus in assembler as well, i would appreciate it if you could send me what you have if that would be ok to

hi, i am engg. student i am working on usb based project. i want some refrence for transferring data between two microcontrollers i.e. in bteween tusb3200 & AT89C51. plz send req. information at

Hi Arshad. Most of the implementations of Modbus are quite large. My application demands a very simple data transfer from a Siemens PLC with Modbus interface to an external display displaying a 16-bit variable. How large do you think the code should be. Can you please send your source code so that I can see how it can be done?

thanks / rgds


By Anda Asgara on 11 August, 2006 - 10:35 pm


my final project is about MODBUS protocol to using a microcontroller,
would you send that assembly language source code to me....
my e-mail:

best regards,
Anda Asgara

Mr Arshad may send me the assembler source code for modbus for use in my hobby project.


By Anonymous on 25 June, 2007 - 12:37 pm

I am working with protocol Modbus and microcontroller UPSD3254. I would like to communicate with this microcontroller through Modbus, but I don't know much about Modbus protocol. I need some help. I need some examples. Can you help me? I appreciate your help.

I m working on modbus serial communication using rs 232. I have to write a c program for slave (p89v51rd2) which i m unable to write. Also how do v send a pdu? and what do function codes do..?? kindly help.. and plz send the code at
thanking u..!


You can download C source code for microcontroller (PIC) from


we have d code for pic..
we have converted it 2 89v51 also bt it is not working..n v r nt able 2 understand some of d functions for pic i.e d readmbframe and read regresponse...kindly help..

1 out of 1 members thought this post was helpful...

Your friendly local Moderator here.

>we have d code for pic..
>we have converted it 2 89v51 also bt it
>is not working..n v r nt able 2
>understand some of d functions for pic
>i.e d readmbframe and read
>regresponse...kindly help..

As a courtesy to others who read this forum, please do not use text speak. I actually do not know what "n v r nt able 2" means. I got "not able to", but the rest might as well be gibberish. I think others who read this forum have the same problem.

Thank you,
Peg Ferraro, moderator

By elabbassy on 11 July, 2011 - 7:50 am

checkout this website:
it covers almost of MCUs

By automationcorner on 11 July, 2011 - 6:54 am

You can use a component like dll or activeX.
You can find it in

Hi, Ramandeep,

Very first understand the MODBUS protocol.
You can find it from

Just try to prepare query structure & send it over UART, You will get response. Compare the response with the Response structure of the protocol.

This should be your first step.

Do Not try to find ready-made code. It will create problem while troubleshooting in future & at that time You will be stuck.

No one will provide Ready-made code for free.

Dixit Solanki

By Narayanan VS on 24 August, 2011 - 11:52 pm

Hello Mr.Dixit,

Your point is very valid and I'm trying the same. I basically have doubt in implementing the "silent signal" for 3.5 character time to indicate start or stop of transmission. Can you help me?

Kind regards,
VS Narayanan


I am working in a program to communicate a microcontroller STM32F103RB with a PLC Phoenix Contact. The PLC is the master and the micro is the slave. So... could someone send me some code for this project? Its RTU and RS485 port.



By R.Jayapal on 10 May, 2012 - 12:31 am


I am working in a program to introduce modbus capability in my project. My project uses ATmega32 microcontroller. I am checking the communication to PC through Modscan 32 software loaded in it. It is not successful. Can anybody give us a sample code in ATmega32 or any tips to solve this? I am unable to understand 3.5 character delay specified.



Im currently working on a project by assigning the MODBUS device address/modbus setting into a slave device. i have to hardcore the modbus setting into MC9RS08KB4CWJ chip in order to have the slave device to communicate with my Moxa gateway.

I looking for some sample MODBUS coding that able to hardcore into my chip, so that it can be recognize by the Master.

Your help is highly appreciated.
My email is

Thank you.