cancel
Showing results for 
Search instead for 
Did you mean: 

How to load 8-bit hex value in integer array.

Mohan1
Associate III

Hello,

I am trying to communicate between stm32 and charger ic(bq25700a) and i am using I2C communication protocol.For that i have to transmit hex value in such a way that 8-bit LSB first and then 8-bit MSB.

I am transmitting hex value 0A00, so i am taking LSB in a array buf1[2]=00 and

MSB in buf1[3]=0A, but when i run the code ,getting error like 'invalid suffix "A" on integer constant'.

Please give me any suggestion.

Thanks.

int Buf1[4];
 while (1)
  {
          Buf1[0]=0x24;       //slave address+write
	  Buf1[1]=0x12;
          Buf1[2]=00;          //LSB Data
	  Buf1[3]=0A;        //MSB Data
	  HAL_I2C_Master_Transmit(&hi2c1,0x12,Buf1,4,100);
}

7 REPLIES 7
Ozone
Lead II

Buf1[1]=0x12;

...

Buf1[3]=0A; //MSB Data

Can't you see the difference ?

I marked it in bold characters.

@Ozone​ Thanks for your response sir,i know what are you trying to say but my doubt is how can i load MSB Data i.e.0A in buffer or should i do like:

Buf1[3]=0x0A

But it wiil become 16-bit and required data is 8_bit.

> But it wiil become 16-bit and required data is 8_bit.

I don't really understand what the problem is.

I2C knows only byte transfers, so the two byte must be (can only be) transferred separately.

Transfer the LSB first.

> ... my doubt is how can i load MSB Data i.e.0A in buffer or should i do like:

> Buf1[3]=0x0A

In your first post, you wrote:

Buf1[0]=0x24; //slave address+write

Buf1[1]=0x12;

And the compiler did not complain.

I suggest to get a good C language tutorial, and work through. The constraints for decimal, hexadecimal and octal number literals are well-defined.

@Ozone​ Thanks for your reply sir,i get my answer.Actually i was confused in Buf1[3]=0x0A ,I was thinking that it was 16-bit,but it is a 8-bit.

Thank you sir once again for your kind reply sir.I am very new to this environment.

dbgarasiya
Senior II

@Mohan​  you should study basics of digital numbers,

Best of luck

@dbgarasiya​ Thanks for your suggestion sir.

you are welcome @Mohan​