2020-01-21 09:32 PM
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);
}
2020-01-21 10:15 PM
Buf1[1]=0x12;
...
Buf1[3]=0A; //MSB Data
Can't you see the difference ?
I marked it in bold characters.
2020-01-21 10:57 PM
@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.
2020-01-22 12:02 AM
> 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.
2020-01-22 12:33 AM
@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.
2020-01-25 12:28 AM
@Mohan you should study basics of digital numbers,
Best of luck
2020-01-27 01:46 AM
@dbgarasiya Thanks for your suggestion sir.
2020-01-27 02:34 AM
you are welcome @Mohan