Skip to main content
Mohan1
Associate III
January 22, 2020
Question

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

  • January 22, 2020
  • 7 replies
  • 1880 views

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);
}

This topic has been closed for replies.

7 replies

Ozone
Principal
January 22, 2020

Buf1[1]=0x12;

...

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

Can't you see the difference ?

I marked it in bold characters.

Mohan1
Mohan1Author
Associate III
January 22, 2020

@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.

Ozone
Principal
January 22, 2020

> 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.

dbgarasiya
Senior
January 25, 2020

@Mohan​  you should study basics of digital numbers,

Best of luck

Mohan1
Mohan1Author
Associate III
January 27, 2020

@dbgarasiya​ Thanks for your suggestion sir.

dbgarasiya
Senior
January 27, 2020

you are welcome @Mohan​