Is it possible for me to use the same F2837x GPIO pin as input and an output in Simulink?

7 Ansichten (letzte 30 Tage)
So I am working on a project that uses a reflectance sensor (https://www.pololu.com/product/961) that requires to be charged before I can read the reflectance value that the sensors sends back. In the section "Interfacing the QTR-8RC Outputs to Digital I/O Lines" from the linked website I need to set the I/O line to an output and then to an input. I was wondering if there was a way I could do that in Simulink?

Akzeptierte Antwort

Venkatesh Chilapur
Venkatesh Chilapur am 8 Apr. 2019
Hi Farhan,
Yes, you can achieve this configuration in simulink.
To begin with you may need to add the following lines of code in the system initialize block under 'System init function execution code' section. These blocks are part of custom code blocks found under simulink coder.
EALLOW;
//enable the pull up
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0;
//Load output latch and drive pin high
GpioDataRegs.GPASET.bit.GPIO0 = 1;
//Pin muxing selection
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;
//Enable output
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;
EDIS;
As an example using this code I would set GPIO0 pin to output and set it high to begin with.
Lateron you can set the same pin as input by using the memory copy block.
For this to happen we need to update the GPADIR register as below:
//Enable input
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO0 = 0;
EDIS;
Using memory copy block we can read-modify-write particular register bitfield.
Attached model is able to acheive the same.
Notice the use of custom code options in the second memory copy block.
Regards,
Venkatesh C
  1 Kommentar
Mike Buba
Mike Buba am 30 Nov. 2022
Hi Venkatesh,
can you please confirm if this would work when writing to a ePWM register?
In your example you are not reading a single bit, but &GpioCtrlRegs.GPADIR.bit
When I try to read, for example, &EPwm2Regs.TBCTL.bit.PHSDIR, I get a compiling error: taking the address of a bit field is not allowed.
What would be the approach for reading and writing to a PHSDIR value?
Kind regards.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by