Use the same pin as input and output alternatively

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Use the same pin as input and output alternatively

945件の閲覧回数
ppz
Contributor II

Hello. Currently I try to implement a driver for a One Wire device to use it on KW41Z board and struggle to make a basic pin setup.

I see only two options of resolving the question inclined in the topic title: either there should be two configuration of a pin with input and output directions set respectively and the pin init function should be called each time I need to change the direction, or the port registers should be changed manually.

Can you say which way is better, and if the second one (with port registers) is more appropriate, can you help me with the port registers setup?

Best regards.

ラベル(2)
1 返信

797件の閲覧回数
mjbcswitzerland
Specialist V

Hi

If you want to change pin direction efficiently it is not wise to perform the complete initialisation each time (it will work but is slower). It is easy to simply use the data direction register as follows:

GPIOx_PDDR |= (pins);

GPIOx_PDDR &= ~(pins);

Or bit band it to avoid the AND/OR operation.

Regards

Mark