cancel
Showing results for 
Search instead for 
Did you mean: 

Use same port to write as well as read

HDesa.1
Senior

Hello,

Currently I am working on a 16-bit parallel interface where I need to write to and read from the same port. For that I am using GPIO_Init LL library every time I do so. Is this the right method? Will the port data also get reset while doing so.

Following are the steps which I follow:

  1. Init the port to output mode.
  2. Write to Port using ODR register.
  3. Wait for few ns and Deinit port & Init the port.
  4. Read from the port using IDR register.

Will step 3 reset the port causing data loss. The problem is I am reading the same data in the IDR register which I have set in ODR.

Could you please guide me through this.

-Regards,

Hrishikesh

-Regards
Hrishikesh
8 REPLIES 8
S.Ma
Principal

First step is to enable clock on gpio cell.

You can read pins at anytime.

Down the road, you may prepare the output level before activating them (glitch potential).

If not using whole 16 bit port (typical case), learn to use BSSR registers which set and clear selected port pins without disabling interrupts....

Why does it cause data loss?

You can reconfigure the Input / Output state of the port via the MODER configuration, you don't need to reset the entire GPIO bank.

Perhaps provide documentation of the protocol you're attempting to implement

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello DeLorean,

I also tried using your suggestion but I am reading the same data in IDR register which I am setting using ODR register.

Is there any alternate option to check if my output pin has set to the input pin after configuring MODER.

-Regards

-Regards
Hrishikesh

Thank you for the suggestion.

Currently, the application which I am working is high speed application(MHz) and I can't carry out this entire stepwise process each and every time. This will actually cause delay in data collection and processing.

Is there any alternate method which you can suggest which will be lot faster.

-Regards

-Regards
Hrishikesh
S.Ma
Principal

It is better to know what your end goal is with some numbers so we can possibly suggest other hw than pure gpio.... please elaborate...

I am driving a device using a parallel interface. I have dedicated a port to communicate with the device. This device has an additional read/write pin which will decide whether I have to write to it or read from it. Now the time delay between the write operation and read operation is in microseconds.

The device operation is as follows:

I write a specific address value to the port during the write operation and the device sends the data on the same port during the read operation. The process is pretty much fast.

Now my concerns are

  1. While changing the mode of the port i.e. from changing it from output mode to input mode does the port gets reset causing the data loss.
  2. Also is there any fast method where I don't need to carry out the entire init and deinit process of GPIO.

In my case, I am reading the same value in the IDR register(during read operation) which I am setting in the ODR register(during write operation).

Do you have any solution for this? Kindly assist me on this.

-Regards

-Regards
Hrishikesh

You don't provide information on the protocol.

Does another pin indicate to the transmitting device it can output to the bus?

Should the GPIO be open collector/drain or tristated to facilitate you driving a signal back?

IDR should reflect what's seen at the pins, does this conflict with data as you see it on a logic analyzer?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

For example, study an STM32 with FMC to interface parallel external memories and displays. In this case, it is hw managed from memory read/write...