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 ?
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
Hi,
if(SIUL2.GPDI[3].R) // PA3 high / SW4 pressed
{
//LED ON
}
else /PA3 low / SW4 released
{
//LED OFF
}
BR, Petr
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
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
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.
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