uart_echo.c(584): warning: #69-D: integer conversion resulted in truncation
GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,~GPIO_PIN_7); //TXEN-4=0 发送
uart_echo.c: 1 warning, 0 errors
为什么用~GPIO_PIN_7会有这提示,不管那个口的第7脚。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
uart_echo.c(584): warning: #69-D: integer conversion resulted in truncation
GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,~GPIO_PIN_7); //TXEN-4=0 发送
uart_echo.c: 1 warning, 0 errors
为什么用~GPIO_PIN_7会有这提示,不管那个口的第7脚。
Hao
这个跟哪个IO没有关系,或者说跟硬件没有关系。在驱动库中有下面的定义
#define GPIO_PIN_7 0x00000080
当将GPIO_PIN_7取反操作后, 其值变为0xFFFFFF7F,即 ~GPIO_PIN_7 = 0xFFFFFF7F
而GPIO的DATA寄存器是8位的,同时GPIOPinWrite的第三个变量的数据类型是uint8,所以会进行将0xFFFFFF7F(超过255)传递到函数的时候,就会出现截断。只截取7F这低八位。对实际效果没有影响。
如果对GPIO某位进行清零操作,比如该处对7pin清零,你可以使用下面的代码:
GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,GPIO_PIN_6); //TXEN-4=0 发送
其他不是一样也会超过
比如#define GPIO_PIN_6 0x00000040
当将GPIO_PIN_6取反操作后, 其值变为0xFFFFFFBF
也超过255
而且发现TM4C1230E6PM,PD7无法置为高电平
GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,GPIO_PIN_7);
TM4C123x系列MCU的PD7和PF0默认为NMI功能;且这两个脚的功能切换需要先进行解锁。
详细信息请参考Datasheet中的Commit Control的内容:
10.2.4 Commit Control
The GPIO commit control registers provide a layer of protection against accidental programming of
critical hardware peripherals. Protection is provided for the GPIO pins that can be used as the four
JTAG/SWD pins and the NMI pin (see “Signal Tables” on page 1330 for pin numbers). Writes to
protected bits of the GPIO Alternate Function Select (GPIOAFSEL) register (see page 671), GPIO
Pull Up Select (GPIOPUR) register (see page 677), GPIO Pull-Down Select (GPIOPDR) register
(see page 679), and GPIO Digital Enable (GPIODEN) register (see page 682) are not committed to
storage unless the GPIO Lock (GPIOLOCK) register (see page 684) has been unlocked and the
appropriate bits of the GPIO Commit (GPIOCR) register (see page 685) have been set.
Hao
是这样的,其他的值一样会超过。不过我在下面的语句中并没有执行取反操作。
GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,GPIO_PIN_6); //TXEN-4=0 发送
只是将bit7置零而已。