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 😀
4.6k views

Related Posts

@Ankita Katdare · Aug 27, 2014

Swipe Telecom has launched a new smartphone called the Swipe Sense that has an inbuilt fingerprint sensor, a feature made popular with Apple's iPhone 5S and 5C smartphones. The Swipe...
3.1k views

@dc11see · May 9, 2012

All we know is 3-phase electricity. But has anyone thought of 4-phase electricity? Is it even possible?
8.2k views

@ashok98107 · Aug 5, 2012

i want to trace my wife having mobile number my business in delhi and my wife lives in mahenderagarh (haryana)
8k views

@PREM SUNDEEP · Jun 22, 2012

please give information about admissions in M.TECH through GATE in AP universities or private colleges? stipend is available colleges and qualifications of stipend?
3.4k views

@Gourav94 · Mar 15, 2016

I just want to know that if i got a admission in pg- vlsi course in Pune with a good b.tech score Is there any confirmation of job And howm...
3.6k views