CrazyEngineers Archive
Old, but evergreen and popular discussions on CrazyEngineers, presented to you in read-only mode.
@shahrul • 12 Feb, 2010
Anybody know the modbus protocol? It can connect to PIC by RS232 connection and PIC can do UART coding. Just want to know how the modbus RTU operation? I keep exploring this and will update the progress.
@shahrul • 19 Feb, 2010 Now, I see the pattern.

Example read holding register.
Request protocol:
Slave ID: 1 byte
Function code: 1 byte
Starting Address: 2 bytes
Quantity of address: 2 bytes
CRC-16: 2 bytes
Response protocol:
Slave ID: 1 byte
Function code: 1 byte
Byte count: 1 byte
Register value: (2*Quantity of address) bytes
CRC-16: 2 bytes
This is the example Tx and Rx data
Tx: 01 03 00 00 00 03 05 CB
Rx: 01 03 06 00 01 00 01 00 04 4C B6
Last 2 bytes for Tx and Rx is CRC-16 checking. My further question is, how to calculate CRC-16?
@shahrul • 24 Feb, 2010 Now, I get the CRC-16 function.
Example
unsigned int data[]={0x01,0x03,0x00,0x00,0x00,0x03};

int CRC16(int DataLength){
unsigned int i,j,CheckSum;
CheckSum=0xFFFF;
for (j=0;j<DataLength;j++){
    CheckSum=CheckSum^response[j];
    for(i=8;i>0;i--){
        if((CheckSum)&0x0001==1) CheckSum=(CheckSum>>1)^0xA001;
        else CheckSum=CheckSum>>1;}}
CRC_high=(CheckSum>>8)&0x00FF;    
CRC_low=CheckSum&0x00FF;
CheckSum=((CheckSum>>8)&0x00FF)|((CheckSum<<8)&0xFF00);
return CheckSum;
}
will return value CRC=0x05CB
@shahrul • 04 Mar, 2010 Now, I have problem on parity bit. I have done 8bit UART, that is NONE PARITY.
The parity bit is setup with 9th bit. I try send this, but it fail at certain data.
response[0]=0x01;
response[1]=0x03;
response[2]=0x06;
response[3]=0x00;
response[4]=0x00;
response[5]=0x00;
response[6]=0x01;
response[7]=0x00;
response[8]=0x02;
CRC16(9);
response[9]=CRC_low;
response[10]=CRC_high;}

for(i=0;i<=10;i++){
TX9D=even_parity(response);
uart_transmit(response);}
@Ashraf HZ • 05 Mar, 2010 This is quite informative stuff. Keep us updated on your progress 😀
2.8k views

Related Posts

@Yashi Das · Aug 1, 2015

Everyone needs a little inspiration throughout their career. Inspiration is what keeps us motivated and passionate about what we do. So,here's my experience at Doordarshan. I got to know about...
11k views

@Ankita Katdare · Apr 29, 2014

What this young researcher from Vanderbilt University has achieved can make it possible to develop nanowires way thinner than human hair using electron beams. Junhao Lin, A Ph.D. student at...
3.9k views

@Ankita Katdare · Aug 23, 2012

Materials engineers continue to be at the forefront in many areas of science. Materials science and engineering influences our lives each time we buy or use a new device, machine,...
4.5k views

@fantasy_craze · Jul 13, 2013

Hi, My rank is 118 ( A+B+C). Can I get any tuition fee waiver???total fee is around 80000/-can anyone tell me ?
1.5k views

@Kaustubh Katdare · Oct 25, 2015

I'm wondering if there's any service provider, payment gateway in India that allows you to make payments from your current mobile balance. For example, if I'm buying something that costs...
9.4k views