This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Does an alternative way exist to change a GPIO state without using the bit structure???

Other Parts Discussed in Thread: CONTROLSUITE

Essentially, I am looking for an alternative way to write this code, but without using the bit structure:

GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;

I want to find an alternative because I have run into problems with integrating code into Matlab Simulink with respect to auto-code generation for CCS v3.3. So, for my application, I want to use some code to continually read a position register on an external RDC board, and this code is contained inside of an "S-Function Builder" block in Simulink. The problem occurs when I build the project, and it says that I can't use the EALLOW, EDIS, or bit structure commands because it cannot recognize them. I'm not sure why this is the case, because code using bit stuctures works in Simulink blocks like 'System Start' and 'Model Source'

  • Hi Jonathan,

    I think I recognize that code snippit as being from controlSUITE. I will move this to the C2000 forums where the experts there can offer their suggestions.

    Thanks

    ki

  • Jonathan,

    I'm not sure finding an alternate method would help you because this register is still EALLOW protected.  This is a protection feature which you can only write to this register after an EALLOW instruction.

    The only other possible solution I'm aware of (haven't tested) is to write directly to the address.  I am doubtful you can write to a specific bit this way though.  You can easily find the address by adding it to the watch window in CCS and right clicking and say "View Memory at Address" or something along those lines.  Then you can try using

    (*address) = new value;

    But again, you would still need to disable EALLOW protection first.  Instead of just using EALLOW try changing it to asm(" EALLOW"); to see if it recognizes this.

    Kris

  • Kris,

    Thanks for the reply. I also had concerns about the EALLOW protection, but I think I've found a work-around for my case. Generally, I had a segment of code with some lines that used EALLOW protected registers, and some lines that did not. Fortunately, the EALLOW protected lines came first in my code, so I just seperated those out, and placed them into the 'System Start' code block in Simulink. Then, I took the lines that weren't EALLOW protected and kept those in the S-function builder. In Simulink, when an S-function builder is used, it must also be built by pressing a Build button, which is similar, but seperate from the Build button for the overall Simulink model that builds and auto-code generates a project for CCS v3.3. Essentially, two builds are needed, but the first build must be from the S-function Builder, which didn't (in my case) have the ability to "see" the necessary include files for using the bit-fields of TI (although this may still be possible, I just haven't figured that part out).

    At first, I had this basic code:

    EALLOW;

    GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;

    GpioCtrlRegs.GPBDIR.bit.GPIO34  = 1;

    EDIS;

    for(;;)

    {   

        GpioDataRegs.GPBSET.bit.GPIO34 = 1;

        GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

        GpioDataRegs.GPBSET.bit.GPIO34 = 1;

        GpioDataRegs.GPACLEAR.bit.GPIO30 = 1;

        GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;

        (*(volatile unsigned int *)theta ) = (*(volatile unsigned int *)0x4000);

    }

    And, I removed the EALLOW protected lines GPBMUX1 and GPBDIR to the 'System Start' block, and kept the rest in the 'Outputs' section of the S-function Builder.

    In the S-function builder, I replaced the bit-field lines with these lines:

    for(;;)

    {  

        (*(volatile unsigned int *)0x6FCA) = (0x0004); /*Set GPIO34 high */

        (*(volatile unsigned int *)0x6FCC) = (0x0004); /*Set GPIO34 low */

        (*(volatile unsigned int *)0x6FCA) = (0x0004); /*Set GPIO34 high */

        (*(volatile unsigned int *)0x6FC5) = (0xC000); /*Set GPIO30, GPIO31 low */

        (*(volatile unsigned int *)position) = (*(volatile unsigned int *)0x4000); /* Place the value on the XINTF into the variable position*/

    }

    I used the 'System Control and Interrupts' Guide (sprufb0d) to find the addresses of the GPBSET, GPBCLEAR, etc. Then, I figured out the word to write to this address that would only change the bits that I wanted to change.

    Do you have any insights or pitfalls that I should look out for when implementing this idea? It seems to work, but now I have other issues, like how to read a value to the position value every step or interrupt, instead of just in a loop (which is just a trial situation right now).