CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18f452 modbus problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ali



Joined: 08 Jun 2010
Posts: 1

View user's profile Send private message

18f452 modbus problem
PostPosted: Tue Jun 08, 2010 2:04 am     Reply with quote

Code:

#include <stdio.h>
#include <stdlib.h>
#define MODBUS_BUS SERIAL
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_EXT

#define MODBUS_TYPE MODBUS_TYPE_MASTER
#define MODBUS_SERIAL_RX_PIN PIN_B0
#define MODBUS_SERIAL_TX_PIN PIN_B1
#define MODBUS_SERIAL_BAUD 19200
#define MODBUS_SLAVE_ADDRESS 10

#include "modbus.c"

char full_message[10]={'$','R','F','Z','Z','E','N','D',0xD,0xA};
int16 temp;
int8 lsb,msb;
int8 tempson1,tempson2;
int i;

void read_all_holding()
{

   if(!(modbus_read_holding_registers(MODBUS_SLAVE_ADDRESS,1024,8)))
   {
      //Started at 1 since 0 is quantity of coils//
      for(i=1; i < (modbus_rx.len); ++i)
        fprintf(COM_A,"%X ", modbus_rx.data[i]);
   }
   else
   {
       fprintf(COM_A,"Exception %X", modbus_rx.error);
   }
   
  /*
   modbus_read_holding_registers(MODBUS_SLAVE_ADDRESS,1030,2);

   for(i=1; i < (modbus_rx.len); ++i)
        fprintf(COM_A,"%X ", modbus_rx.data[i]);
   */     
     
}

void main()

   setup_wdt(WDT_ON);
 //  setup_timer_0(RTCC_INTERNAL);
 
  // enable_interrupts(INT_EXT);

   //SET_TRIS_B( 0xf0 );
   modbus_init();
   tempson1=0xD;
   tempson2=0xA;
   fprintf(COM_A,"$C2");
 
 while(1)
 {
  read_all_holding();
   
   output_low(PIN_B4);
   //fprintf(COM_A,full_message);
  // fprintf(COM_A,full_message);
 
   delay_ms(400);
   //fprintf(COM_A,"denemebilgisayarı");
    output_high(PIN_B4);
    //delay_ms(1000);
 }

}

This is my hardware test program. I was compiling and only one warning message:
Quote:

Interrupt disabled during call to prevent re-entrancy:(modbus_calc_crc)

I send to read holding register command. My second uart to pc send me only time out error. But if I can use 232 serial monitor I can see all correct register value.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 08, 2010 7:18 am     Reply with quote

Since you did not post the modbus_calc_crc routine it is hard for us to say what is going on.
Linuxbuilders



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

PostPosted: Sat Mar 03, 2012 6:27 pm     Reply with quote

inside modbus.c line 729
replace modbus_calc_crc(c);

with following:

Code:
         #if (MODBUS_SERIAL_TYPE == MODBUS_ASCII)
            modbus_serial_lrc+=c;
         #else
            unsigned int8 uIndex ; // will index into CRC lookup table

            uIndex = (modbus_serial_crc.b[1]) ^ c; // calculate the CRC
            modbus_serial_crc.b[1] = (modbus_serial_crc.b[0]) ^ modbus_auchCRCHi[uIndex];
            modbus_serial_crc.b[0] = modbus_auchCRCLo[uIndex];
         #endif

_________________
Help "d" others and then you shell receive some help from "d" others.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group