How to Use User Switch on DEVKIT-MPC5748G?

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

How to Use User Switch on DEVKIT-MPC5748G?

2,389 Views
Elsa_24
Contributor II
Hi, I am trying to familiarize myself with the DEVKIT-MPC5748G. So far I have been able to turn on a user LED. Now I want to control the LED (on and off) with a user switch. I have activated for example the PORT PA3 connected to the User Switch4 as input already. But how do I set the condition "If User Switch4 is pressed then the LED lights up and otherwise the LED stays off"?) Thanks
0 Kudos
Reply
7 Replies

2,264 Views
polisetty
Contributor II

Hi I am trying to write a program  to control the LED (on and off) with a user switch. If I press the switch the LED must ON and otherwise it remains OFF.(by using MPC5748G controller)

can any one tell me how to write program for that ? 

0 Kudos
Reply

2,225 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I guessed this was discussed in this thread.
For example add below code to the simple "hello_Z4_1" example

SIUL2.MSCR[PA10].B.OBE = 1; /* Pad PA10 (10): OBE=1. On EVB active low DS4 LED */
SIUL2.MSCR[PA3].B.IBE = 1; /* Pad PA3 (3): IBE=1. On EVB switch SW4 */

while(1)
{
     if(SIUL2.GPDI[PA3].R) // PA3 high / SW4 pressed
    {
       SIUL2.GPDO[PA10].R = 0;//LED ON
    }
    else //PA3 low / SW4 released
    {
       SIUL2.GPDO[PA10].R = 1;//LED OFF
    }
}

BR, Petr

0 Kudos
Reply

2,383 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if(SIUL2.GPDI[3].R) // PA3 high / SW4 pressed
{
   //LED ON
}
else   /PA3 low / SW4 released
{

   //LED OFF
}

BR, Petr

2,377 Views
Elsa_24
Contributor II

Hi PetrS,

Thanks for your answer.

I tried to do as you suggested but I got an error in the if condition:

<<request for member 'GPDI' in something not a structure or union>>

how to solve the problem?

Here is the corresponding part of my code. The erector signals at the level of the condition in the if

if(SIUL2.GPDI[3].R)
{
PINS_DRV_WritePin(PTA, 10, 1);
}
else
{
PINS_DRV_WritePin(PTA, 10, 0);

}

 

PS: I have activated PORT PA3 in SIUL2 as an input already. it corresponds to GPIO 3

0 Kudos
Reply

2,371 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

check how registers are defined in the device header file.
Under SDK you can use PINS_DRV_ReadPins function.

The usage should be
pin_value = ((uint16_t)(1<<(pin))&PINS_DRV_ReadPins(port))>>(pin);

In your code you can can have e.g.

if((uint16_t)(1<<(3))&PINS_DRV_ReadPins(PTA))
{
     PINS_DRV_WritePin(PTA, 10, 1);
}
else
{
     PINS_DRV_WritePin(PTA, 10, 0);
}

BR, Petr

0 Kudos
Reply

2,336 Views
Krishnaja
Contributor II

Hi @PetrS ,

I am  also getting same error in if loop. "Request for member 'GPDI' in something not a structure or union", I have enclosed the project. 

Please tell me how to resolve the error.

Thanks

Krishnaja.

0 Kudos
Reply

2,315 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

did you read my latest post? 
Either use driver function
if((uint16_t)(1<<(3))&PINS_DRV_ReadPins(PTA))
or according header file use 
if(SIUL2->GPDI[3])

BR, Petr

0 Kudos
Reply
An error has occurred when reading existing sub-variable "Language_PG_Configuration"; see cause exception! The type of the containing value was: extended_hash+string (lithium.coreapi.webui.template.models.NamedValueByNameTemplateModel wrapped into f.e.b.StringModel) ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign redirect_lingo_page_url = web... [in template "language_macro_header.ftl" at line 173, column 1] - Reached through: #include "language_macro_header.ftl" [in template "Language_translator_Dashboard" at line 3, column 1] ----