AN206373 F²MC/FR Family All series Method of confirming data in serial Communications.pdf

AN206373
F2MC/FR Family, All series, Method of confirming data in serial Communications
When MCU transmit/receive the data by the serial communications interface, there is a possibility of receiving wrong
data by the noise. Therefore, this application note explains the method of confirming data by using the checksum.
About the serial communications interface specification, please confirm the hardware manual of each MCU..
Contents
1
2
1
Introduction ..................................................................1
Method of using checksum in serial communications ..2
Document History.............................................................. 3
Introduction
When MCU transmit/receive the data by the serial communications interface, there is a possibility of receiving wrong
data by the noise. Therefore, this application note explains the method of confirming data by using the checksum.
About the serial communications interface specification, please confirm the hardware manual of each MCU.
www.cypress.com
Document No. 002-06373 Rev. *A
1
F2MC/FR Family, All series, Method of confirming data in serial Communications
2
Method of using checksum in serial communications
This chapter shows the method of calculating checksum by putting the 16 bit length data on some address. The
example of C language program to calculate checksum is shown as follows.
unsigned short calc_checksum( unsigned short *addr, int size)
{
unsigned long sum;
unsigned long checksum;
sum = 0;
while( size > 1 ){
sum+= *(addr++);
size-= 2;
}
if( size > 0 ){
sum+= (*addr) & 0xff00;
/* If byte data remains at the end, it is added */
}
sum = (sum & 0xffff) + (sum >> 16); /* To 16 bit length. */
checksum = ~sum;
/* Complement of one */
}
The transmitted side calculates checksum by the above-mentioned and adds it at the end of the transmission data.
The received side calculates by all receive data including checksum.
There is no error if the result of the calculation on the received side is 0xFFFF.
The mistake of the transmitting/receiving data can be easily confirmed by such a method.
www.cypress.com
Document No. 002-06373 Rev.*A
2
F2MC/FR Family, All series, Method of confirming data in serial Communications
Document History
2
Document Title: AN206373 - F MC/FR Family, All series, Method of confirming data in serial Communications
Document Number: 002-06373
Revision
ECN
Orig. of
Change
Submission
Date
**
-
YUIS
08/05/2008
First Edition
*A
5293564
YUIS
06/02/2016
Migrated Spansion Application Note “AN07-00155-1E” to Cypress format.
www.cypress.com
Description of Change
Document No. 002-06373 Rev.*A
3
F2MC/FR Family, All series, Method of confirming data in serial Communications
Worldwide Sales and Design Support
Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find
the office closest to you, visit us at Cypress Locations.
Products
®
®
PSoC® Solutions
ARM Cortex Microcontrollers
cypress.com/arm
Automotive
cypress.com/automotive
PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP
Clocks & Buffers
cypress.com/clocks
Cypress Developer Community
Interface
cypress.com/interface
Forums | Projects | Videos | Blogs | Training | Components
Lighting & Power Control
cypress.com/powerpsoc
Memory
cypress.com/memory
PSoC
cypress.com/psoc
Touch Sensing
cypress.com/touch
USB Controllers
cypress.com/usb
Wireless/RF
cypress.com/wireless
Technical Support
cypress.com/support
PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corporation. All other trademarks or registered trademarks
referenced herein are the property of their respective owners.
Cypress Semiconductor
198 Champion Court
San Jose, CA 95134-1709
Phone
Fax
Website
: 408-943-2600
: 408-943-4730
: www.cypress.com
© Cypress Semiconductor Corporation,2008-2016. This document is the property of Cypress Semiconductor Corporation and its subsidiaries, including
Spansion LLC (“Cypress”). This document, including any software or firmware included or referenced in this document (“Software”), is owned by
Cypress under the intellectual property laws and treaties of the United States and other countries worldwide. Cypress reserves all rights under such
laws and treaties and does not, except as specifically stated in this paragraph, grant any license under its patents, copyrights, trademarks, or other
intellectual property rights. If the Software is not accompanied by a license agreement and you do not otherwise have a written agreement with
Cypress governing the use of the Software, then Cypress hereby grants you a personal, non-exclusive, nontransferable license (without the right to
sublicense) (1) under its copyright rights in the Software (a) for Software provided in source code form, to modify and reproduce the Software solely for
use with Cypress hardware products, only internally within your organization, and (b) to distribute the Software in binary code form externally to end
users (either directly or indirectly through resellers and distributors), solely for use on Cypress hardware product units, and (2) under those claims of
Cypress’s patents that are infringed by the Software (as provided by Cypress, unmodified) to make, use, distribute, and import the Software solely for
use with Cypress hardware products. Any other use, reproduction, modification, translation, or compilation of the Software is prohibited.
TO THE EXTENT PERMITTED BY APPLICABLE LAW, CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD
TO THIS DOCUMENT OR ANY SOFTWARE OR ACCOMPANYING HARDWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. To the extent permitted by applicable law, Cypress reserves the right to
make changes to this document without further notice. Cypress does not assume any liability arising out of the application or use of any product or
circuit described in this document. Any information provided in this document, including any sample design information or programming code, is
provided only for reference purposes. It is the responsibility of the user of this document to properly design, program, and test the functionality and
safety of any application made of this information and any resulting product. Cypress products are not designed, intended, or authorized for use as
critical components in systems designed or intended for the operation of weapons, weapons systems, nuclear installations, life-support devices or
systems, other medical devices or systems (including resuscitation equipment and surgical implants), pollution control or hazardous substances
management, or other uses where the failure of the device or system could cause personal injury, death, or property damage (“Unintended Uses”). A
critical component is any component of a device or system whose failure to perform can be reasonably expected to cause the failure of the device or
system, or to affect its safety or effectiveness. Cypress is not liable, in whole or in part, and you shall and hereby do release Cypress from any claim,
damage, or other liability arising from or related to all Unintended Uses of Cypress products. You shall indemnify and hold Cypress harmless from and
against all claims, costs, damages, and other liabilities, including claims for personal injury or death, arising from or related to any Unintended Uses of
Cypress products.
Cypress, the Cypress logo, Spansion, the Spansion logo, and combinations thereof, PSoC, CapSense, EZ-USB, F-RAM, and Traveo are trademarks or
registered trademarks of Cypress in the United States and other countries. For a more complete list of Cypress trademarks, visit cypress.com. Other
names and brands may be claimed as property of their respective owners.
www.cypress.com
Document No. 002-06373 Rev.*A
4