Click here to Skip to main content
15,607,338 members
Home / Discussions / Hardware & Devices
   

Hardware & Devices

 
QuestionNUC for a light shared development data server? Pin
maze33-Sep-18 0:28
professionalmaze33-Sep-18 0:28 
QuestionHuawei E3372 USB Dongle Pin
Hazel J Chua23-Aug-18 19:27
Hazel J Chua23-Aug-18 19:27 
QuestionSIM900 - connection issue Pin
MateoGlowinski1-Aug-18 21:30
professionalMateoGlowinski1-Aug-18 21:30 
QuestionSOLVED Raspberry Pi interrupt C/C++ - sample code / tutorial ? Pin
Vaclav_30-Jun-18 2:41
Vaclav_30-Jun-18 2:41 
QuestionIntel mini motherboards / MIDI IN .. Single Board Computer ? Pin
ApplesAreGood24-Apr-18 6:44
ApplesAreGood24-Apr-18 6:44 
AnswerRe: Intel mini motherboards / MIDI IN .. Single Board Computer ? Pin
Richard MacCutchan24-Apr-18 7:00
mveRichard MacCutchan24-Apr-18 7:00 
QuestionNeed help with internal timing constraint in FPGAs Pin
Member 137693108-Apr-18 21:33
Member 137693108-Apr-18 21:33 
GeneralModbus RTU with function code1 Pin
Member 105152258-Apr-18 21:08
professionalMember 105152258-Apr-18 21:08 
Dear all,

I am trying to implement modbus RTU with function code 1 . The code i have written implemented for function code 3 . i will get proper response for function code 3. When i implemented for function code 1 i am getting invalid checksum response error.
The crc function is working fine . I have checked modscan32, excel sheet of simplymodbus website.
Simply Modbus - Enron Modbus Function Code 01 - Read Boolean Variables[^]


[^]


On-line CRC calculation and free library[^]


CRC calculation code

unsigned int crc_fn(unsigned char *dpacket,unsigned int len) // CRC Function(Error calcualtion)
{
 unsigned int crc = 0xffff,poly = 0xa001;
 unsigned int i=0; 
   
 for(i=0;i<len;i++)
 {
    crc^= dpacket[i];
    for(j=0;j<8;j++)
    {
     if(crc & 0x01)
     {
      crc >>= 1;
      crc ^= poly;
     }
     else
    crc >>= 1;
    }
 }
 return (crc); 
}


Main function
void Serial_Data()
{
 
    
    unsigned int address,crc1,crc2;
 unsigned char length,i;
    unsigned char Data_Len_Count;
    unsigned char length1;
     
     
    // Serial_1_Send_byte(rxbuf[0]);
    crc2=crc_fn(&rxbuf[0],6); //crc function for received protocol from request 
         __delay_ms(10); // Changed on 20.01.2017
  if((rxbuf[6]==(unsigned char)(crc2))&&(rxbuf[7]==((unsigned char)(crc2>>8))))
     {
                
  if(rxbuf[0]==Device_ID )
  {
            
   if(rxbuf[1]==READ_REG)
   {
    address=(((unsigned int)(rxbuf[2]<<8))+((unsigned int)(rxbuf[3]))); 
    if(rxbuf[5]>=1)
    {
                   
     length1=(rxbuf[5]<249)?(rxbuf[5]+7)/8:0X20;
                    length=(rxbuf[5]*1);
     address=(address*1); 
     ser_data[0]=Device_ID ;
     ser_data[1]=rxbuf[1];
     ser_data[2]=length; 
     ser_data[3]=rxbuf[6];
     ser_data[4]=rxbuf[7];
     ser_data[5]=length1;
     ser_data[6]=00;
     ser_data[7]=00;
     ser_data[8]=00;
     ser_data[9]=00; 
                    
     
     crc_data[0]=Device_ID ;
     crc_data[1]=rxbuf[1];
     crc_data[2]=length;
                     
     j=3;
     for(i=address;i<((address+length));i++)
     {
      crc_data[j++]=ser_data[i+3];
                       // ChecksumCal(length);
     }
     crc1 =crc_fn(&crc_data[0],(length+3)); //crc function for response protocol from the device
                   
                    Serial_1_Send_byte(ser_data[0]);
     Serial_1_Send_byte(rxbuf[1]);
     Serial_1_Send_byte(ser_data[2]);
                    
     for(i=address;i<((address+length));i++)
     {
      Serial_1_Send_byte(ser_data[i+3]);
                        
     }
     Serial_1_Send_byte((unsigned char)crc1);
     Serial_1_Send_byte((unsigned char)(crc1>>8));
                     Serial_1_Send_byte(crc_msb);
                             Serial_1_Send_byte(crc_lsb);
                    
                    
                    
                    for(i=0;i<30;i++)
                    {
                       Serial_1_Send_byte(0);
                    }
                    
    } 
   } 
   __delay_ms(5); 
       }
       
 }
  index=0;
 rec_flag = 0;


My suspection is on Storing the values inside register and Sending them for CRC check.Because send response is going well, i get error while getting response.
GeneralRe: Modbus RTU with function code1 Pin
Gerry Schmitz9-Apr-18 3:54
mveGerry Schmitz9-Apr-18 3:54 
QuestionRAM image of DVD? Pin
kalberts7-Apr-18 3:35
kalberts7-Apr-18 3:35 
AnswerRe: RAM image of DVD? Pin
Gerry Schmitz7-Apr-18 7:04
mveGerry Schmitz7-Apr-18 7:04 
GeneralRe: RAM image of DVD? Pin
kalberts8-Apr-18 21:26
kalberts8-Apr-18 21:26 
GeneralRe: RAM image of DVD? Pin
Gerry Schmitz9-Apr-18 2:05
mveGerry Schmitz9-Apr-18 2:05 
GeneralRe: RAM image of DVD? Pin
kalberts9-Apr-18 2:30
kalberts9-Apr-18 2:30 
GeneralRe: RAM image of DVD? Pin
Gerry Schmitz9-Apr-18 3:10
mveGerry Schmitz9-Apr-18 3:10 
AnswerRe: RAM image of DVD? Pin
Randor 11-Apr-18 15:21
professional Randor 11-Apr-18 15:21 
QuestionIs android or windows tablet any good for occasional coding? Pin
Kanter6665-Apr-18 22:57
professionalKanter6665-Apr-18 22:57 
AnswerRe: Is android or windows tablet any good for occasional coding? Pin
OriginalGriff5-Apr-18 23:07
mvaOriginalGriff5-Apr-18 23:07 
AnswerRe: Is android or windows tablet any good for occasional coding? Pin
Gerry Schmitz6-Apr-18 7:52
mveGerry Schmitz6-Apr-18 7:52 
AnswerRe: Is android or windows tablet any good for occasional coding? Pin
Eddy Vluggen9-Apr-18 3:50
professionalEddy Vluggen9-Apr-18 3:50 
QuestionWin 10 Crash again (captured DMP file) - hw Pin
raddevus17-Mar-18 7:37
mvaraddevus17-Mar-18 7:37 
AnswerRe: Win 10 Crash again (captured DMP file) - hw Pin
Munchies_Matt17-Mar-18 7:50
Munchies_Matt17-Mar-18 7:50 
GeneralRe: Win 10 Crash again (captured DMP file) - hw Pin
raddevus17-Mar-18 8:24
mvaraddevus17-Mar-18 8:24 
AnswerRe: Win 10 Crash again (captured DMP file) - hw Pin
Gerry Schmitz17-Mar-18 11:22
mveGerry Schmitz17-Mar-18 11:22 
AnswerRe: Confused about cat5,cat5e, and cat6 Ethernet cables Pin
Richard MacCutchan25-Feb-18 22:01
mveRichard MacCutchan25-Feb-18 22:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.