Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Make a bit to zero without using "~" and affecting other bits in a register - ARM Compiler 6 (ARMClang compiler)

Status
Not open for further replies.

Raguvaran

Newbie level 5
Newbie level 5
Joined
Jul 1, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
Hi, I am in basic level of embedded C. Using Keil for STM32 programming. For bit set and reset i use "|=" and "&=~". Below is a code

GPIOA->ODR |= (1<<5); // PA5 = 1
GPIOA->ODR &=~ (1<<5); // PA5 = 0


While using ARM Compiler Version 5 there is no issue.
In ARM Compiler 6 (ARMClang compiler), I am getting a warning while using "~" that

main.c(28): warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
GPIOA->ODR &=~ (1<<5); // PA5 = 0
~~^~~~~~~~

By reading a document "Migrate ARM Compiler 5 to ARM Compiler 6", I understood the Bit-field Signedness in ARM Compiler 5 is default unsigned and in ARM Compiler 6 is default signed

My Question is,
1) Now how i have make a bit to zero without using "~" and affecting other bits in a register?
2) Is it ok to use "|=" to make a bit to 1?
3) Is any other effective way to make a bit to zero or one without affecting other bits in a register?

Kindly apology me if my question is very basic,
Thank you in advance
 

Attachments

  • warning_msg_keil.png
    warning_msg_keil.png
    11 KB · Views: 165
  • Migrate ARM Compiler 5 to ARM Compiler 6.pdf
    1.1 MB · Views: 162

Hi,

A warning is no error, thus I assume everything is working as expected.

*****
I'm no expert either....so what I'd try is
* typecasting: set "(unsigned int)" before "(1<<5)"
* or use HAL functions
* or use BRR instruction

Just did an internet search "keil bit clear arm". (Didn't you do something similar on your own before?)
There are a lot of interesting documents.
There seems to be a BIC function and a CLEAR_BIT function...

You may also try other internet search like: "keil arm clear port pins"

Klaus
 

    Raguvaran

    Points: 2
    Helpful Answer Positive Rating
Why not a simple AND to clear the bit ? If compiler still complains then do a cast
first, if your signedness is known before the cast....

Not a C expert, but thats what I would try.

Regards, Dana.
 

    Raguvaran

    Points: 2
    Helpful Answer Positive Rating
Hi,

A warning is no error, thus I assume everything is working as expected.

*****
I'm no expert either....so what I'd try is
* typecasting: set "(unsigned int)" before "(1<<5)"
* or use HAL functions
* or use BRR instruction

Just did an internet search "keil bit clear arm". (Didn't you do something similar on your own before?)
There are a lot of interesting documents.
There seems to be a BIC function and a CLEAR_BIT function...

You may also try other internet search like: "keil arm clear port pins"

Klaus
Thank you Klaus

This code shoes no error
{
GPIOA->ODR |= (1<<5); // PA5 = 1
delayMs(500);
GPIOA->ODR &=~ (unsigned int)(1<<5); // PA5 = 0
delayMs(500);
}


and also tried SET_BIT and CLEAR_BIT functions as you mentioned.
{
SET_BIT(GPIOA->ODR, GPIO_ODR_OD5); // PA5 = 1
delayMs(500);
CLEAR_BIT(GPIOA->ODR, GPIO_ODR_OD5); // PA5 = 0
delayMs(500);
}


As reading further I understood that using BSRR and BRR is efficient compared to using ODR. Because accessing ODR takes more cycles.
Thank you for your guidance.

Hope this help others.

--- Updated ---

Why not a simple AND to clear the bit ? If compiler still complains then do a cast
first, if your signedness is known before the cast....

Not a C expert, but thats what I would try.

Regards, Dana.
Thank you for your reply.

direct AND may affect other bits in a register.

Maybe if i am wrong, kindly correct me..
 

To set a bit to zero, execute AND with a number consisting of 1's in all the other bit positions.

Example, to clear the rightmost bit of 8 bits, execute AND and 254. It leaves the leftmost 7 bits unchanged.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top