warning: #61-D: integer operation result is out of range

integer operation result is out of range

 //Set GPIO Direction
#define DHT22_IO_IN()  {GPIOA->CRL &= 0X0FFFFFFF;GPIOA->CRL |= (8 << 4*7);}	
#define DHT22_IO_OUT() {GPIOA->CRL &= 0X0FFFFFFF;GPIOA->CRL |= (3 << 4*7);}	

在进行STM32 IO端口方向设置时出现以下警告:
warning: #61-D: integer operation result is out of range
warning: #68-D: integer conversion resulted in a change of sign

查明原因:
编译器默认signed int即32位有符号整数类型,而1<<31实际为0x80000000,这样就有可能改写了符号位(最高位)

修改如下:

#define DHT22_IO_IN()  {GPIOA->CRL &= 0X0FFFFFFF;GPIOA->CRL |= ((uint32_t)8 << 4*7);}	
#define DHT22_IO_OUT() {GPIOA->CRL &= 0X0FFFFFFF;GPIOA->CRL |= ((uint32_t)3 << 4*7);}
发布了13 篇原创文章 · 获赞 16 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_32969455/article/details/83501182