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.

GPIO compiler bugs in setting consecutive IOs

I need to set GPIO2 and 3 , 1 and 0 respectively. However if I write them in consecutive statements GPIO2 never sets. On the scope I see a narrow pulse on GPIO2 of about 250 us .
If I add a dummy i++ as shown below it works.
GpioDataRegs.GPADAT.bit.GPIO2= 1;
i++;
i++;
i++;
GpioDataRegs.GPADAT.bit.GPIO3 = 0;
It happens with GPIOs10 and 11 also.  (consecutive Ios). Its a showstopper as I need to set and reset Ios hundreds of places in my application and my confidence is low on it. I cannot possibly put i++ everywhere.
the GPIOtoggle command works perfectly as I suspect its a multiple assembly instructions.
I suspect its a compiler bug. pls help. I am using piccolo 28069
  • Hi Anusheel,

    Can you be a bit precise on what exactly are you looking for? In short what kind of waveform on which GPIOs?

    anusheel nahar said:
    I need to set GPIO2 and 3 , 1 and 0 respectively.

    Is it PWM kind of waveform you're looking for?

    Regards,

    Gautam

  • i just need GPIO2 high and GPIO3 low. If I put those statements consecutively ,GPIO2 behaves erratically. instead of remaining hi , there is a pulse of 250 us. I had to add dummy i++ in between to make it work. same thing with GPIO10 and 11. seems to be compiler stupidity.

  • anusheel nahar said:
    i just need GPIO2 high and GPIO3 low.

    Try this simpe code out:

    EALLOW;
       //GPIO
       GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;  // GPIO2 = GPIO2
       GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;   // GPIO2 = output
       
       GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;  // GPIO3 = GPIO3
       GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;   // GPIO3 = output
    EDIS;
       
       
       GpioDataRegs.GPASET.bit.GPIO2 = 1;  
       GpioDataRegs.GPACLEAR.bit.GPIO3 = 1;  

    Regards,

    Gautam

  • All that settings is correct.

    GpioDataRegs.GPASET.bit.GPIO2 = 1;  
       GpioDataRegs.GPACLEAR.bit.GPIO3 = 0; 

    if I write this GPIO2 is always 0 except for very narrow pulse of 500 us . I put them in for loop with delay and I see pulses periodically



    if I write this
     GpioDataRegs.GPASET.bit.GPIO2 = 1;  
    i++; GpioDataRegs.GPACLEAR.bit.GPIO3 = 0;

    where i is a dummy , it behaves correctly. The code you sent wont/isnt working properly.
    i can always do this way but it reduces my confidence in compiler /TI things in general and is very irritating . Whenever I toggle some io , i dont know whether the next (unrelated) statement will mess it up . I think its a serious show stopper and TI shud investigate it.



  • That's very unusual, Anusheel. Its working perfectly on my controlStick!

    Please mention your CCs and compiler version so that a TIer can take care of you query. I'm also looping this to a CCS expert.

    Regards,

    Gautam

  • Anusheel,

    This is a well known behavior of GPIOs on C2000.  

    Please refer to the following pages for more information.

    http://processors.wiki.ti.com/index.php/General_Purpose_IO_(GPIO)_FAQ_for_C2000#Q:_Back-to-back_DAT_register_writes_do_not_work_as_expected

    http://e2e.ti.com/support/microcontrollers/c2000/f/171/t/319643.aspx

  • Thanks for the info, Mark! In short one will have to use a NOP instruction in between.

    Regards,

    Gautam

  • Mark,

    The way I read the first article shows in its example code that the problem is with GPADAT. Then it goes on to say:

    "One solution is to use CLEAR/SET registers for this example."

    Anusheel's code is already using GPACLEAR/GPASET.

  • Gene Morgan1 said:
    Anusheel's code is already using GPACLEAR/GPASET.

    Yes, but in the wrong way.

    The statement:

    GpioDataRegs.GPACLEAR.bit.GPIO3 = 0;

    has no effect. Only writes of "1" will clear the GPIO.

    Regards, Andy

  • Ah, just using the correct regs is a necessary though not sufficient condition.

    Thanks for the catch.