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.

can we modify the GPIO direction and value in the Interrupt program? it's really strange! sos

hallo ! 

Servus!

i want to change the GPIO state , namly pin direction and the pin values afterwards in a External Iinterrupt program .

but i found it's strange,

1. if i debug the program step by step , it works perfectly.

2. but when i let it run. the values that i catch in Expessions are wrong. 

did anyone know why? how could i solve it?

interrupt void xint2_isr(void)
{

	// enter the communication program accroding to the FPGA_CLK

	       //////////////// state 0/////////////////////////
						if(state_flag == 0)                // state 1 default
							{
							GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;

								 io_dir = 0; 			// GPIO as Output
								 Gpio_Select();
								 GpioDataRegs.GPACLEAR.bit.GPIO3 = 1;

								state_flag =1;
							}



				//////////////// state 1/////////////////////////
					if(state_flag == 1  )                // state 1 default
					{



						 Get_DATA();   // this is the function that i used to get the DATA 

						 GpioDataRegs.GPASET.bit.GPIO3 = 1;

						state_flag =2;
					}

..........
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;   //clear the irq-flag
}


void Get_DATA(void)
{

		GpioDataRegs.GPADAT.bit.GPIO31 = 1;
		GpioDataRegs.GPADAT.bit.GPIO29 = 0;
		GpioDataRegs.GPADAT.bit.GPIO23 = 1;
		GpioDataRegs.GPADAT.bit.GPIO21 = 0;
		GpioDataRegs.GPADAT.bit.GPIO19 = 1;
		GpioDataRegs.GPADAT.bit.GPIO17 = 0;
		GpioDataRegs.GPADAT.bit.GPIO27 = 1;
		GpioDataRegs.GPADAT.bit.GPIO25 = 0;
		GpioDataRegs.GPCDAT.bit.GPIO85 = 1;
		GpioDataRegs.GPBDAT.bit.GPIO49 = 0;
		GpioDataRegs.GPADAT.bit.GPIO11 = 1;
		GpioDataRegs.GPADAT.bit.GPIO9 = 0;
		GpioDataRegs.GPADAT.bit.GPIO7 = 1;



}



thanks a lot! guys!

  • Hi,

    In your Get_DATA() function, for setting GPIO pins to '1' or clearing it to '0', please use the GPxSET and GPxCLEAR register instead of GPxDAT register. GPxDAT register gets updated with status on GPIO pin (at IO level) and due to internal delay it takes some time get updated which casues a problem for RMW operations during run time. When you step through it works fine becasue between steps there is enough time for GPxDAT register to get updated with value on IOs.

    GPxDAT should be used to read the GPIO pin status. 

    Regards,

    Vivek Singh

  • thanks for your answer!

    you are right! i just thought about that.

    but question is

    1. if i put the  Get_DATA() function in the main function, it runs correctly even though i use the GPXDAT.

    2.  how could i send a lot of values to a lot of GPIO pins, if we need to use only GPXSET or GPXCLEAR or GPXTOGGLE?

        should i use e.g.GpioDataRegs.GPADAT.all = 0xaaaa5555; ? but if there is some pins( or some pins) that predefined as input.

        OR, the ONLY way is to set the pin one by one ...

        like that

    						GpioDataRegs.GPASET.bit.GPIO31 = 1;
    						GpioDataRegs.GPACLEAR.bit.GPIO29 = 1;
    						GpioDataRegs.GPASET.bit.GPIO23 = 1;
    						GpioDataRegs.GPACLEAR.bit.GPIO21 = 1;
    						GpioDataRegs.GPASET.bit.GPIO19 = 1;
    						GpioDataRegs.GPACLEAR.bit.GPIO17 = 1;
    						GpioDataRegs.GPACLEAR.bit.GPIO27 = 1;
    						GpioDataRegs.GPASET.bit.GPIO25 = 1;
    						GpioDataRegs.GPCCLEAR.bit.GPIO85 = 1;
    						GpioDataRegs.GPBSET.bit.GPIO49 = 1;
    						GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;
    						GpioDataRegs.GPASET.bit.GPIO9 = 1;
    						GpioDataRegs.GPACLEAR.bit.GPIO7 = 1;

      it is something troublesome, or?

    thanks for your  answer

    regards.

    dong

  • Hi Dong,

    1. if i put the  Get_DATA() function in the main function, it runs correctly even though i use the GPXDAT.

    I don't think there should be any change in bahavior of this function when getting executed inside ISR or outside of ISR.  Updating GPxDAT like this  will cause issue in both case. Could you please check this again.

      should i use e.g.GpioDataRegs.GPADAT.all = 0xaaaa5555; ? but if there is some pins( or some pins) that predefined as input.

    Yes, you could do this if you want to SET and CLEAR the multiple pins at same time. Write to pins which are configured as INPUT will be ignored.

    Regards,

    Vivek Singh