Is it possible for me to use the same F2837x GPIO pin as input and an output in Simulink?
6 vues (au cours des 30 derniers jours)
Farhan Rahman le 6 Avr 2019
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?
Venkatesh Chilapur le 8 Avr 2019
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.
//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;
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;
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:
GpioCtrlRegs.GPADIR.bit.GPIO0 = 0;
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.