Hi! I've the following problem! I receive via CAN a 16-Bit value, I'll use for some calculations on a Siemens C167CR, und transmit the result again back via CAN! The following code works fine on a PC: (test 16 ist declared as an unsigned int, the byte_high and byte_low as char) test16 = byte_high; test16 = test16 << 8; test16 = test16 | byte_low; The way back: byte_low = test16; byte_high = (test16 >> 8); also works fine (on the PC)! But the code doesn't work on the C167! It seem's, that the C167 doesn't make the conversion back not correct. Thanks for your tips! SVEN
(test 16 ist declared as an unsigned int, the byte_high and byte_low as char) Shouldn't the chars also be unsigned? Otherwise, you're likely to run into sign-extension problems. also works fine (on the PC)! But the code doesn't work on the C167! Welcome to the world of platform-dependence! What size is an unsigned int on your PC? What exactly happens on your target? Have you tried stepping it in the simulator?
See Mark Odell's site for examples of platform-independent data type definitions: http://www.embeddedfw.com/
Remember, unsigned int on 32-bit OS's like Windows are 32-bits. For your 167, probably only 16. Be sure to always use unsigned vars. when bit shifting, including your chars. Try unsigned short on the PC to match the size of the 167's unsigned int. Like Andrew Neil (thanks Andrew) said, see my web page's Coding Conventions document for known size typedefs. - Mark