ericparggah
Newbie level 5
- Joined
- Oct 18, 2008
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,352
Hi,
I am trying to write and read a 16-bit value to a memory based smart card using I2C. Write and Read functions are as shown below:
The problem is that when I display the various bytes to the LCD, I get the correct Values. However, when i then concatenate the two bytes i get something different from what I expect. For example, 2557 ---> 0x09FD
So HiByte = 0x09, LoByte = 0xFD.
When displayed individually, they are correct. And when I shift the upper byte 0x09 8 places the left and display i get 2304 which is correct. But when i OR the LoByte then there is a problem.
Note: HiByte = I2Cread(0x00), LoByte = I2Cread(0x01).
Any help would be greatly appreciated.
Thanks
I am trying to write and read a 16-bit value to a memory based smart card using I2C. Write and Read functions are as shown below:
Code:
void WriteToSmartCard(unsigned int Value)
{
unsigned char HiByte, LoByte;
LoByte = Value; // Assign the 8-LSb to the variable Addres/Value >>= 8; // Shift the 8-LSB out of the variable Value
Value >>= 8;
HiByte = Value; // Assign the remaining 8-MSb to the variable AddressHi
I2Cwrite((0x00), HiByte);
I2Cwrite((0x01), LoByte);
}
unsigned int ReadSmartCard()
{
CardAmount = I2Cread(0x00);
CardAmount <<= 8;
CardAmount |= (I2Cread(0x01);
return CardAmount;
}
So HiByte = 0x09, LoByte = 0xFD.
When displayed individually, they are correct. And when I shift the upper byte 0x09 8 places the left and display i get 2304 which is correct. But when i OR the LoByte then there is a problem.
Note: HiByte = I2Cread(0x00), LoByte = I2Cread(0x01).
Any help would be greatly appreciated.
Thanks