View previous topic :: View next topic |
Author |
Message |
mojsa2000
Joined: 18 May 2010 Posts: 78
|
using modbus with EEPROM |
Posted: Sun May 15, 2011 2:58 am |
|
|
Hi
I want to do a project with two PICs & at24c512(EEPROM) & two max487.
in this project I want to be able to read/write data from/to 24c512 in rs485 .in this way I
defined a PIC as master and the other as slave.I used max487 to convert data (RS232<-->Rs485).
I've read modbus protocol and understood it as well.but there is some questions for me:
must I define coils & registers & inputs base on at24c512 memory map?How should I do it?
I could understand the modbus rules but I cant to use it on this project.please help me.
thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sun May 15, 2011 3:51 am |
|
|
Seriously, do you need ModBus?.
The 'point' about ModBus, is that it is a standard,m and if you want to talk to other devices, or let other devices talk to you, then it is well worth using. But if _you_ are the only device talking to the memory, then you do not need the complexity of ModBus. Just use the RS485, as if you are using a normal RS232 like, and define your own much simpler protocol.
What do you need to do?.
Read/Write bytes?.
Read/Write blocks?.
Are you going to have multiple devices on the bus, or just the master slave pair?.
If the latter, then something simple, like a single character 'command' 'w', and 'W' perhaps for 'write byte', and 'write block' respectively, and 'r', and 'R' for the reads. Then follow with an address, and the single byte, or block of bytes respectively. Then a checksum. Then the 'slave' device responds just with something like 'OK' if the checksum is correct, and with the requested data for a read (also with a checksum), or 'ERR' if the checksum is not OK.
The master on reads can check the checksum, and if this is not OK, just request the data again, and on the write, if the 'ERR' reply is seen, try again.
Much smaller and simpler than the ModBus code, quicker to....
If you are going to have multiple devices, then a device address would need to be added, and extra commands, but basically, unless you _need_ to talk ModBus, because another device is going to use the bus, don't add an unnecessary complexity....
Best Wishes
Best Wishes |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Sun May 15, 2011 5:18 am |
|
|
Dear Ttelmah
thanks for your reply.
I want to connect a group of PICs in a HIGH POWER ELECTERICAL UNIT to a PC.The PC do a simple act.it send a request to PICs to read data that stored in PICs External EEPROMs.this data is for logging to show changes.I dont know which is better if I select a modbus or simple RS485 protocol.
is it necessary to use Rs485 & modbus together?
please help me.
best wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun May 15, 2011 5:40 am |
|
|
As Ttelmah points out , Keep It Simple ! The hardware will be the same , RS-485, so start with bare bones codes.Get the PICs up and running a simple program, see how it runs.Small tight code that YOU design will be better than MODBUS 'bloatware' that hogs memory and machine cycles.
You don't need a sledghammer to hang a picture on the wall. Wrong tool for the job.
It is far easier to debug code YOU cut than some 'cut and pasted' hodegpodge from the 'Net'.
Start simple and build on what you learn.InterPIC communications can be very,very easy to cut,heck CCS supplies examples in the examples folder ! |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Sun May 15, 2011 6:13 am |
|
|
Hi
thanks for your attentions
I have a important question.
How can I order to a pic to read/write an address on eeprom in modbus protocol?
best wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun May 15, 2011 9:06 am |
|
|
You'll have to find a CCS C programmer that will do the code.
Providing the hardware is the same as your original post and you clearly specify the scope(details) of the project it shouldn't take more than a week or so or about $2,500.
Obviously the programmer will have to have extensive knowledge of MODBUS, as well as a MODBUS system for testing.
Upgrades or modifications to the original program code typically will cost between $75- $100 per hour.
Be advised that this is CODE only. No PCB manufacture, no hardware, just code. |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Sun May 15, 2011 12:14 pm |
|
|
Dear temtronic
Hi
thanks for youe advices but I want to do this project myself.I know about
modbus protocol and pic structure too.maybe I am not a professional programmer but I like to challenge.as a proverb:"if you like some one,
dont give him fish but teach him fishing ".
if everybody know about it please help me.I want to read/write data over
rs485 line.the master is a pic and slaves are PICs that have EEproms(I2C support).
I cant understand somethings in modbus.for example in "data" packet,we send some information such as address and quantity of bytes.function code
also tells what action must perform.now,I want to know how tell to PIC that
which address in EEPROM must be read/write.
best wishes |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun May 15, 2011 12:23 pm |
|
|
Search for the word modbus in this forum and you should find a lot of info. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun May 15, 2011 12:37 pm |
|
|
Quote: | I cant understand somethings in modbus.for example in "data" packet,we send some information such as address and quantity of bytes.function code also tells what action must perform.now,I want to know how tell to PIC that which address in EEPROM must be read/write. |
I don't think, that the question is particularly related to MODBUS operation or PIC programming in general. You are asking how to organize the communication in your project.
You possibly selected MODBUS, because it presents process data as addressable registers. In fact there's a simple, straigthforward scheme, that maps the complete 24512 data to 32k registers of 16 Bit width. But I don't know if it's suitable for your application. Implement the MOSBUS register read and write actions as EEPROM accesses and you're done. |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Mon May 16, 2011 5:19 am |
|
|
Hi
I searched web and read more and more documents about MODBUS and achieved good results.
my problem was that I couldn't apply MODBUS protocol rules in my program because I thought that the address must be a specified place in a device memory but now,I know the address tell us which subroutine (function) in software must be run ( every subroutin has a special address) and function code tell us which operation must be done(some function codes are defaults and we can define some function codes)
is that I understood true?
if it is wrong plaes help me.
thanks
Last edited by mojsa2000 on Mon May 16, 2011 5:36 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Mon May 16, 2011 5:35 am |
|
|
Not to sure why you want to use MODBUS for your project, but you do say you are familiar with it so I suggest a bit more 'googling' and reading.
If your project is to read/write data to eeprom from one PIC to another PIC via RS485, then by using the CCS supplied examples, you can 'cut and paste' a working solution in a few hours. Been there done that. One of the reasons I chose CCS was the wealth of code examples they supplied 15 years ago. Now, with the advent of 'googling', you can probably find someone else's complete code from their 'final project' from school. |
|
|
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
|
Posted: Wed May 18, 2011 1:26 pm |
|
|
I've actually designed exactly what you want! If you are interested in a drop in working solution let me know and I will ask my client about supply for you. It's fully electrically isolated on each RS485 port (3off) so probably a little overkill. All ports can access the memory simultaneously via Modbus protocol.
|
|
|
|