TI中文支持网
TI专业的中文技术问题搜集分享网站

[分享]F2837x GPIO使用DAT問題

假設 GpioDataRegs.GPADAT.all的值為0x0000

此時設定GPIO1與GPIO2為1

GpioDataRegs.GPADAT.bit.GPIO1 = 1; 

GpioDataRegs.GPADAT.bit.GPIO2 = 1;

當設定GPIO2的時候會將  GpioDataRegs.GPADAT.all讀出(此時GPIO1為0),再將GPIO的bit設置為1再存入GpioDataRegs.GPADAT.all。

將導致GPIO1為0,手冊上的解決方法為

1.GPIO1與GPIO2之間增加延遲

2.使用GPASET

使用手冊:

GpioDataRegs.GPADAT.bit.GPIO1 = 1; //I1 performs read-modify-
write of GPADAT GpioDataRegs.GPADAT.bit.GPIO2 = 1; //I2 also a read-modify-
write of GPADAT. //GPADAT gets the old value of GPIO1 due to the delay
The second instruction will wait for the first to finish its write due to the write-followed-by-read
protection on this peripheral frame. There will be some lag, however, between the write of (I1) and the
GPyDAT bit reflecting the new value (1) on the pin. During this lag, the second instruction will read the
old value of GPIO1 (0) and write it back along with the new value of GPIO2 (1). Therefore, GPIO1 pin
stays low.
One solution is to put some NOPs between instructions. A better solution is to use the
GPySET/GPyCLEAR/GPyTOGGLE registers instead of the GPyDAT registers. These registers always
read back a 0 and writes of 0 have no effect. Only bits that need to be changed can be specified
without disturbing any other bit(s) that are currently in the process of changing.

Green Deng:

是的。这个情况在所有C2000系列产品上都有,所以,一般如果是操作GPIO翻转电平的话不建议使用GPxDAT寄存器。推荐使用GPxSET,GPxCLEAR,或者GPxTOGGLE。

赞(0)
未经允许不得转载:TI中文支持网 » [分享]F2837x GPIO使用DAT問題
分享到: 更多 (0)