cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO as bidirectinal pin

robosoft
Associate II
Posted on August 18, 2008 at 11:49

GPIO as bidirectinal pin

3 REPLIES 3
robosoft
Associate II
Posted on May 17, 2011 at 09:54

Hi,

I need P3.6 as a bidirectional pin.

P3.2 and P3.3 are used for UART1. (UART works fine)

This is my initialisation.

Code:

<BR> GPIO_InitTypeDef GPIOInit; <BR> SCU_APBPeriphReset(__UART1,DISABLE); <BR> SCU_APBPeriphReset(__GPIO3,DISABLE); <BR> <BR> SCU_APBPeriphClockConfig(__UART1,ENABLE); <BR> SCU_APBPeriphClockConfig(__GPIO3,ENABLE); <BR> <BR>//RxD1 <BR> GPIOInit.GPIO_Pin = GPIO_Pin_2; <BR> GPIOInit.GPIO_Direction = GPIO_PinInput; <BR> GPIOInit.GPIO_Type = GPIO_Type_PushPull; <BR> GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable; <BR> GPIOInit.GPIO_Alternate = GPIO_InputAlt1; <BR> GPIO_Init(GPIO3,&GPIOInit); <BR> <BR>//TxD1 <BR> GPIOInit.GPIO_Pin = GPIO_Pin_3; <BR> GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Disable; <BR> GPIOInit.GPIO_Direction = GPIO_PinOutput; <BR> GPIOInit.GPIO_Alternate = GPIO_OutputAlt2; <BR> GPIO_Init(GPIO3,&GPIOInit); <BR> <BR> <BR>//P3.6 for DS2401 and heartbeatLED <BR> GPIOInit.GPIO_Pin = GPIO_Pin_6 ; <BR> GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable; <BR> GPIOInit.GPIO_Direction = GPIO_PinOutput; <BR> GPIOInit.GPIO_Type = GPIO_Type_OpenCollector; <BR> GPIOInit.GPIO_Alternate = GPIO_OutputAlt1; <BR> GPIO_Init(GPIO3,&GPIOInit); <BR>

I set the port to '1' using the library function

Code:

<BR>GPIO_WriteBit(GPIO3,GPIO_Pin_6,Bit_SET); <BR>

When I connect the pin to ground I read '1' using

Code:

<BR>GPIO_ReadBit(GPIO3,GPIO_Pin_6)); <BR>

It seems that I do not read the actual state of the PIN but rather the contents of the outputregister.

I try to change the settings of GPIOInit.GPIO_IPConnected to Disbale, same result :(

What is wrong here ?

Luc Vercruysse.

[ This message was edited by: robosoft.ontwikkeling on 14-08-2008 11:06 ]

matthew239955_stm1
Associate II
Posted on May 17, 2011 at 09:54

The GPIO_ReadBit function returns values from the GPIO data register. Unfortunately for your needs, if the pin is configured as an output then reading that bit will only return the value that you wrote to the data register. You must configure a pin as an input to read the actual value from the pin.

With that said, it looks like you are trying to talk to a 1-wire bus peripheral, and as far as I know you are not going to be able to do that with a single GPIO line on the ARM. Searching for ARM & 1 wire bus will yield all kinds of exotic workarounds.

There is no such thing as a bidirectional GPIO pin. Some of the peripheral functions that use bidirectional lines (like I2C) will route the input buffer straight to the peripheral. That is what the GPIO_IPConnected member is for. Although in your case, p3.6 is routed to the SPI MOSI, which won't give you any data without an SPI clock input.

The path from the DR to the pin is only one way at a time. Maybe someone with more experience could chime in about the option of reconfiguring the I/O port on the fly. Because the pin goes hi-Z when configured as an input, you would need an external pull up to implement your bus.

robosoft
Associate II
Posted on May 17, 2011 at 09:54

Thanks for reply !

I found out that the only thing I have to do is to switch the Data direction in the DDR to read the data on the GPIO-PIN.

I first have to set the the bit in the DR to '1'. (GPIO must be configured as open collector).

Now I am able to communicate with a &-wire device.

Luc