0

I've been working on I2C and I learned how to initialize, send and receive with I2C communication protocol.

Next, I wanted to run the LCD1602 I2C adapter. But the module has a different bit masking, it turns out that I have to keep a specific bit set so I can control the remaining 7-bits, because otherwise I can't control the upper 4-bits if this bit is 0.

So, I put the 8-bit variable for the bit masking operations in the global section and initialize it with uint8_T bitmasking = 0x08; but it's volatile. I used static keyword, but the bit is not constant.

So what's the solution?

Regards,

1

'static' just avoids reinitialization and is used for local vars in timed interrupts for example.

volatile is another keyword you should not be using without thinking about it and does not appear to be useful for your case. See https://stackoverflow.com/questions/4592762/difference-between-const-const-volatile for more information

The appropiate keyword would be const, which tells the compiler this var mustn't be changed.

But I suspect there is another problem with your code, which will make the compiler throw an error as soon as you use const in the declaration. I assume you are not using the variable correctly. You are meant to use a bitwise OR | in order to set the required bit along your actual data.

So do it like this:

data_byte |= bitmasking;
write8(data_byte);
|improve this answer|||||
  • Well, after thinking about it, I don't know, I don't think it's what I want because it may change anytime. – R1S8K May 10 '17 at 12:08
  • wtf? what may change at any time? – mystery May 10 '17 at 15:54
  • Sorry that method works fine. I figured out another method which is to initialize the variable in the global region with that bit set. Regards, – R1S8K May 13 '17 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.