View previous topic :: View next topic |
Author |
Message |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation help |
Posted: Mon Oct 19, 2009 7:32 am |
|
|
Thanks for your reply
Now one more problem. I want to perform read operations with holding registers. But my data is in the form of float. How can I able to read a floating value from the holding registers????
Hoping a reply
Thanks in advance |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Oct 19, 2009 7:46 am |
|
|
Depends on how float values are represented in the MODBUS data. Unlike other field bus standards, MODBUS has no specified representation of 32-Bit integer and float data, it's a matter of application specific definitions. For this reason, a MODBUS device that makes use of above 16-Bit data formats must exactly specify how. Check the user manual! |
|
|
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation help..... |
Posted: Fri Oct 23, 2009 11:34 pm |
|
|
Sir
Thanks for your help and support. I completed my coding part. But the memory for the compiler is not sufficient. I am using CCS V-4.057. When I compiled it part by part it was working. But when I used my full code the compiler was not supporting. It is showing an error like
Quote: | Out of ROM, a segment or the program is too large MAIN |
Can you please help me?
Hoping a reply.
Thanks in advance. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Oct 24, 2009 9:03 am |
|
|
The most likely reason is, that your application simply doesn't fit the selected PIC type. What has been the ROM utilization before you applied the last changes? |
|
|
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation help |
Posted: Mon Oct 26, 2009 4:05 am |
|
|
Sir,
Thanks for your reply.
I changed the code by using #separate. Now it is working. |
|
|
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation problem |
Posted: Mon Nov 02, 2009 5:26 am |
|
|
sir,
Now my project is over. But the modbus communication speed is not sufficient for my application. I tried with a baud rate of 19,200.But unfortunately it also not sufficient. A baud rate greater than 19,200 showed an error in the #use rs232 function. Is there any other option to increase the communication speed? Please help me.
Hoping a reply
Thanks in advance |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Nov 02, 2009 9:30 am |
|
|
The possible UART baud rates depend on the crystal frequency. With 20 MHz, 57k6 should also work. Otherwise a different crystal would be needed, e.g. one of these special UART frequencies as 18.432 MHz. |
|
|
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation help |
Posted: Sat Nov 07, 2009 5:14 am |
|
|
Thanks for your reply...
Now I am using 20Mhz crystal and it is working.... |
|
|
Lalo_hdzd
Joined: 13 Apr 2010 Posts: 1
|
NEED SOME HELP |
Posted: Tue Apr 13, 2010 9:09 pm |
|
|
Helo I am new at this forum, and I need some help, hope you can help me, because I am running out of time, just have 3 weeks to finish it. By the way this is the first time I use PICs.
I am trying to communicate a PLC with a 18f2550 microcontroller via modbus. I am using the library of modbus given in the CCS with a few modifications (just on the delays), but i am sure it is working fine because it was used by an other person for a pic18f4550 with the same crystal speed and worked perfectly. The hardware I am using is working properly because I tried sending some chars and they where delivered perfectly. The compiler version I am using is v4.104.
The problem is that I wrote a small program testing the library, and checked the request in the tinybootloader, but the package I am sending is 78 78 00 00 78 00 F8 00 78 00 78, which has nothing to do with what I want to send. I am using the 0x05 function of modbus which is write a single coil. Hope can get some help.
Here is the program I tested.
Code: |
#include <18F2550.h>
#FUSES HS //High speed Osc
#FUSES MCLR //Master Clear pin enabled
//#FUSES CPUDIV4 //System Clock by 4
#FUSES NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock=20000000)
#define MODBUS_TYPE MODBUS_TYPE_MASTER
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_BAUD 9600
#define MODBUS_SERIAL_PARIDAD N //E:EVEN, N:NONE, O:-ODD
#define MODBUS_SERIAL_ENABLE_PIN pin_c4 // Controls DE pin c4 puse d2
#define MODBUS_SERIAL_RX_ENABLE pin_c5 // Controls RE pin
#define MODBUS_SERIAL_TIMEOUT 100000 //us
//#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#define MODBUS_SERIAL_RX_PIN pin_c7
#define MODBUS_SERIAL_TX_PIN pin_c6
#define MODBUS_SLAVE_ADDRESS 0x01
#include <mymodbus.c>
int8 nodo=0x01; //Direccion del esclavo
int16 bobina=13; //Numero de la bobina
int16 bobina2=16;
int16 bobina3=15;
int1 estado = true;
void main(){
modbus_init();
do{
modbus_write_single_coil(nodo, bobina, estado);
modbus_write_single_coil(nodo, bobina2, estado);
modbus_write_single_coil (nodo, bobina3, estado);
}while(true);
}
|
Any clue what do I have to change??? Thanks in advance. |
|
|
anupama619
Joined: 10 Sep 2009 Posts: 47
|
Problems when implementing modbus with rs485.... |
Posted: Sat Jun 12, 2010 5:53 am |
|
|
hi all
I successively done modbus implementation. But unfortunately the same code is not working when I am using max485 instead of max232. Can anybody help me?? Thanks in advance. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Jun 12, 2010 8:12 am |
|
|
I expect, that you defined a MODBUS_SERIAL_ENABLE_PIN?
How did you wire MAX485 receiver enable? I have tied it to transmit enable (driven from the said MODBUS_SERIAL_ENABLE_PIN)
and a pullup resistor at the RxD line.
Furthermore, what's the connected peer? How do you know, that it's operating the RS485 interface correctly? Have you implemented
pull-up and pull-down resistor to set the RS485 idle state? |
|
|
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation using rs485 |
Posted: Mon Jun 14, 2010 1:24 am |
|
|
Hi
In my Max485 connection I shortened RE and DE pin and it connected to PIN B5 of the pic16f877a, where RE is the receiver output enable and DE is the driver output enable. And in order to use Max485 I edited modbus transmit function like this
Code: |
exception modbus_write_single_register(int8 address, int16 reg_address, int16 reg_value)
{
output_high(PIN_B5); //MAX485 enabled for transmission
modbus_serial_send_start(address, FUNC_WRITE_SINGLE_REGISTER);
modbus_serial_putc(make8(reg_address,1));
modbus_serial_putc(make8(reg_address,0));
modbus_serial_putc(make8(reg_value,1));
modbus_serial_putc(make8(reg_value,0));
modbus_serial_send_stop();
output_low(PIN_B5); //MAX485 enabled for reception
MODBUS_SERIAL_WAIT_FOR_RESPONSE();
return modbus_rx.error;
}
|
where PIN_B5 is made shorten with RE and DE of Max485.
But it is not working. Can you please tell me where I went wrong.
And in my code I am not using MODBUS_SERIAL_ENABLE_PIN at all.
Where I want to enable this? and to what value? I found some lines in the modbus.c like this
Code: |
#ifndef MODBUS_SERIAL_ENABLE_PIN
#define MODBUS_SERIAL_ENABLE_PIN 0 // Controls DE pin. RX low, TX high.
#endif
#ifndef MODBUS_SERIAL_RX_ENABLE
#define MODBUS_SERIAL_RX_ENABLE 0 // Controls RE pin. Should keep low.
#endif
|
But I am not getting how to enable this. Need some urgent help.
Thanks in advance. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Jun 14, 2010 8:30 am |
|
|
Quote: |
Where I want to enable this? and to what value? I found some lines in the modbus.c like this
|
In the ex_modbus_master.c you will find
Code: |
//The following should be defined for RS485 communication
//#define MODBUS_SERIAL_ENABLE_PIN 0 // Controls DE pin for RS485
//#define MODBUS_SERIAL_RX_ENABLE 0 // Controls RE pin for RS485 |
change to
Code: |
//The following should be defined for RS485 communication
#define MODBUS_SERIAL_ENABLE_PIN 1 // Controls DE pin for RS485
#define MODBUS_SERIAL_RX_ENABLE 1 // Controls RE pin for RS485
|
Assuming you have a half duplex (2 wires) communication, connect DE and RE to PIN B5.
In you code:
Code: |
output_high(PIN_B5); //MAX485 enabled for transmission
output_low(PIN_B5); //MAX485 enabled for reception
|
You do not need to handle this pin, let the compiler to do its job. If you do not see that this pin
is activated while the master is in transmition, re-check the previous definitions and the .lst file.
Could you post your definition of: Code: |
MODBUS_SERIAL_INT_SOURCE // Source of interrupts
|
Humberto |
|
|
anupama619
Joined: 10 Sep 2009 Posts: 47
|
|
Posted: Tue Jun 15, 2010 1:43 am |
|
|
In my code I am using like this:
Code: |
#ifndef USE_WITH_PC
#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7, stream=PC, errors)
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_EXT
#define MODBUS_SERIAL_TX_PIN PIN_B1 // Data transmit pin
#define MODBUS_SERIAL_RX_PIN PIN_B0 // Data receive pin
#define DEBUG_MSG(msg) int i//fprintf(PC, msg)
#define DEBUG_DATA(msg,data) int j//fprintf(PC, msg, data)
#else
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#define DEBUG_MSG(msg) if(0)
#define DEBUG_DATA(msg,data) if(0)
#endif
|
Is it a right way??? Or anything I want to modify?? Hoping a reply. Thanks in advance. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Jun 15, 2010 5:03 am |
|
|
Those definitions are right, it is true also that we need to see them in its context.
The original code keeps the global definitions in a way that you can get the same result without
the risk of mixing them in order to simplify.
Humberto |
|
|
|