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.

Toggling GPIO12 using 28027F

Other Parts Discussed in Thread: MOTORWARE

I am using a custom board using 28027F. I am using Motorware Lab 20 for my project. The board uses RS-485 for SCI communications. The isolator's transmit and received enable pins are shorted. I have set up the communications but I need to toggle the enable pins so as to receive and transmit. I can set the GPIO12 high and low to transmit however it does not toggle. If it is set high (or low) at the beginning (in hal.c) file it retains that value throughout the program. I want to keep it low so that I will always receive communication, set it high only when I am going to transmit. This is the short code I wrote to test it:

In main.c

ReceivedChar = HAL_sciaRead(halHandle);// & 0x00FF;

if(receiveflag==1)
{


//HAL_pieAckInt(halHandle,PIE_GroupNumber_9); // Issue PIE ack INT9

GPIO_setHigh(gpioHandle, GPIO_Number_12);

HAL_sciaWrite(halHandle, 5);

GPIO_setLow(gpioHandle, GPIO_Number_12);
//receiveflag = 0;
}

in hal.c in setupGpio function

// RS-485
GPIO_setMode(obj->gpioHandle,GPIO_Number_12,GPIO_12_Mode_GeneralPurpose);
GPIO_setDirection(obj->gpioHandle,GPIO_Number_12,GPIO_Direction_Output);
GPIO_setLow(obj->gpioHandle, GPIO_Number_12);

...

The pin seems to remain low instead of going high in the if loop.

  • I have tried single stepping through the program. The function in gpio.c seems to execute but nothing actually happens. Similar thing happenes, if I set GPIO 12 to high initially, it becomes high but does not become low when the toggle function is executed. I have also tried using GPIO_toggle function but still the output of that pin does not toggle.
  • Nikhil,

    Your code for toggling GPIO_12 looks OK, I recommend that you try setting a breakpoint at "//RS-485"  line to make sure that these lines of code actually get executed. Furthermore, as you change the level of the output, direction and other bits, you can monitor the watch window to verify that these bits are changing (per System Control and Interrupts Reference Guide for this device)

    If the register bits are changing, but the GPIO_12 is still not toggling, please take a look at your board and make sure no other extrnal signal is also driving GPIO_12.


    Regards,
    PEter

  • Peter,

    I ran that part of code in single steps and monitored the output of GPIO 12 on the CRO. I found out that the code itself is working. As in the pin goes high, then it executes the HAL_sciaWrite function and then the pin goes low again. However when I run the code continuously, I just see a spike on the CRO. The pin goes high momentarily and becomes low again even before the HAL_sciaWrite function writes the data on Tx pin. So even though I get transmission at the output of the processor, nothing gets transmitted from the board.

    Does the sequence of operations change between running continuously and going step by step?

    The purple is the output of GPIO 12 and blue is Tx.

  • Wait till transmission is over before TXEN making low.
    //one simple method is checking again for txEmpty

    void scia_xmit(int a)
    {
    EnableTX();
    while(!SciaRegs.SCICTL2.bit.TXEMPTY);
    SciaRegs.SCITXBUF = a;
    while(!SciaRegs.SCICTL2.bit.TXEMPTY);
    DisableTX();
    }