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,

asked May 9, 2017 at 17:00

1 Answer 1

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);
answered May 9, 2017 at 17:26
3
  • Well, after thinking about it, I don't know, I don't think it's what I want because it may change anytime. Commented May 10, 2017 at 12:08
  • wtf? what may change at any time? Commented May 10, 2017 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, Commented May 13, 2017 at 11:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.