S32k146 S32 Design Studio . Application code Troubleshooting

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32k146 S32 Design Studio . Application code Troubleshooting

342 Views
akhilranga
Contributor IV

Hi there, The following is a code to produce certain type of pulses based on the command mentioned in the code. Butm while i was trying to test the code. I noticed my code pointer is skipping over the delay function which was called in the SendData functtion. So, can any one possibly identify the issue. If so, please help me understand that bug. Thank You

/* Including needed modules to compile this module/procedure */
#include "S32K146.h"
#include "Cpu.h"
#include "clockMan1.h"
#include "pin_mux.h"

volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#include <stdint.h>
#include <stdbool.h>

//#define LED_PORT 	 PORTD
//#define GPIO_PORT	 PTD
//#define PCC_CLOCK	 PCC_PORTD_CLOCK
//#define LED1		 15U
//#define LED2		 16U


  #define GPIOE_PORT 			 PTE
  #define GPIOD_PORT             PTD
  #define Push_Button_Switch      4U
  #define LOCK_COMM  			  7U //Output


//#define Lock_Status   1  //Locked: 1, Unlocked 0


#define LOCK_COMMAND   	 0xAAAA //1010 1010 1010 1010
#define UNLOCK_COMMAND 	 0x5555 //0101 0101 0101 0101



void delay_ms(uint32_t milliseconds)
{
    /* Delay function - do nothing for a number of cycles */
    uint32_t ticks = milliseconds*(SystemCoreClock / 1000);
    while(ticks--){}
}


void BoardInit(void)
{


    /* Initialize and configure clocks
     *  -   Setup system clocks, dividers
     *  -   Configure FlexCAN clock, GPIO, LPSPI
     *  -   see clock manager component for more details
     */
    CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
                        g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
    CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);


    /* Initialize pins
     *  -   Init FlexCAN, LPSPI and GPIO pins
     *  -   See PinSettings component for more info
     */
    PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
}

void sendData( int dataLevel )
{


	if (dataLevel == 1)
	{
		// Data 1:
		// Turn on the LED through LOCK_COMM pin
		//PTE->PCOR |= (1 << LOCK_COMM);
		PINS_DRV_WritePin(GPIOE_PORT,LOCK_COMM,1);
        delay_ms(3);

		// Turn off the LED
		//PTE->PSOR |= (1 << LOCK_COMM);
		PINS_DRV_WritePin(GPIOE_PORT,LOCK_COMM,0);
        delay_ms(1); // Total 4ms delay
	}
	else if (dataLevel == 0)
	{

		// Data 0:
        	// Turn on the LED
		//PTE->PCOR |= (1 << LOCK_COMM);
		PINS_DRV_WritePin(GPIOE_PORT,LOCK_COMM,1);
		delay_ms(1);

        	// Turn off the LED
		//PTE->PSOR |= (1 << LOCK_COMM);
		PINS_DRV_WritePin(GPIOE_PORT,LOCK_COMM,0);
		delay_ms(3); // Total 4ms delay
	}

}
//void initOneWirePin(void)
//{
//    //configure GPIO pin PTE7 for command transmission
//    PTE->PDDR &= ~COMMAND_PIN_MASK; // Set pin as input (pull-up)
//}




int main(void)
{

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  #ifdef PEX_RTOS_INIT
    PEX_RTOS_INIT();                 /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of Processor Expert internal initialization.                    ***/
    BoardInit();
    //initOneWirePin();

    	// Enable clock to PORT E (where the LOCK_COMM is connected)
       // PCC->PCCn[PCC_PORTE_INDEX] |= PCC_PCCn_CGC_MASK;

        // Set pin as GPIO
       // PORTE->PCR[LOCK_COMM] |= PORT_PCR_MUX(1);


        // Set pin as output
       // PTE->PDDR |= (1 << LOCK_COMM);




       // int k = 0;
 // while (k <= 10) //Loop until k reaches 10
  while(1)
        {



	  if ((PTD->PDIR & (1<<4)) == 0)//Red Key Switch ON
	  	{
	  		// send 0xAAAA //1010 1010 1010 1010

	  		delay_ms(5); //sync. head

	  		for (int i = 0; i < 15; i++) {
	  			//sendData(1);
	  			//sendData(0);
	  			sendData((LOCK_COMMAND >> i) & 0x01); // Send each bit of the lock command 1 or 0
	  		}

	  		delay_ms(4); //ACK
	  	}
	  if ((PTD->PDIR & (1<<4)) !=0 )//Red Key Switch OFF
	  	{
	  		// send 0x5555 //0101 0101 0101 0101

	  		delay_ms(5); //sync. head

	  		for (int i = 0; i < 15; i++) {
	  			//sendData(0);
	  			//sendData(1);
	  			sendData((UNLOCK_COMMAND >> i) & 0x01); // Send each bit of the unlock command 1 or 0

	  		}
	  		delay_ms(4); //ACK
	  	}
	  	delay_ms(200);

	  	//k += 1; //increment k by 1

	  	//if(k == 10){
	  	//break;
	  	//}

  }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;) {
    if(exit_code != 0) {
      break;
    }
  }
  return exit_code;
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
}/*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.1 [05.21]
**     for the Freescale S32K series of microcontrollers.
**
** ###################################################################
*/

 

0 Kudos
Reply
1 Reply

316 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @akhilranga,

Try declaring your variable inside the delay function as volatile. The compiler may optimize away that whole function entirely, as it contains no side effects. 

Best regards,
Julián