I'm learning the example project of BlinkLED. And it runs well. However, the example is to make LED2 blink, then I'm trying to modify the code to make other LED blinking. (let's say LED1 as an example)
Original Code:(same as a tutorial)
void pitCh0Handler(void){
PIT_DRV_ClearStatusFlags(INST_PIT1, 0U); /* Clear PIT channel 0 interrupt flag */
SIUL2->GPDO[0] ^= SIUL2_GPDO_PDO_4n_MASK; / * Toggle LED (GPIO 0 connected to user LED 2) */
}
int main(void){
CLOCK_DRV_Init(&clockMan1_InitConfig0);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
INT_SYS_InstallHandler(PIT_Ch0_IRQn, &pitCh0Handler, NULL);
PIT_DRV_Init(INST_PIT1, &pit1_InitConfig);
PIT_DRV_InitChannel(INST_PIT1, &pit1_ChnConfig0);
PIT_DRV_StartChannel(INST_PIT1,0U);
}
Modify area:
change pin mux to PA[4], which represents LED1.
SIUL2->GPDO[4] ^= SIUL2_GPDO_PDO_4n_MASK
Result: LED1 turns on, but never blink.
Does anyone know why?
I think the problem is "SIUL2_GPDO_PDO_4n_MASK", but I couldn't find any pin muxing in the MPC5748G datasheet!
No matter what I search ("SIUL", "GPDO", “GPDI”) inside the datasheet, I receive very limited information. Unlike MPC5744P datasheet, clear and helpful. Or am I looking at wrong data datasheet?
Please helps!
Solved! Go to Solution.
See the description of GPDO register. It's 32bit register which contains four bits to control four pins.
So, GPDO[0] covers GPIOs 0-3. GPDO[1] covers GPIOs 4-7 and so on...
To write PA[4], you need to write GPDO[1] using mask SIUL2_GPDO_PDO_4n_MASK.
(Note: this depends on used header file. Sometimes the GPDO is defined as array of 32bit registers like this, sometimes it's defined as array of 8bit registers, so it is more straightforward. Both options can be used.)
Anyway, if you use SDK, why not to use SDK functions for this? There are functions like PIN_DRV_WritePin, PIN_DRV_SetPins, PIN_DRV_ClearPins, PIN_DRV_TogglePins...
Regards,
Lukas
Hi Junyi,
description of the registers and pin muxing can be found in the reference manual:
https://www.nxp.com/webapp/Download?colCode=MPC5748GRM
There's an excel file attached inside the document:
Regards,
Lukas
Lukas,
Thank you for your reply.
I found the excel, but it didn't solve my question.
For LED2[PA0]:
SIUL2_GPDO_PDO_4n_MASK = 0x01000000
then how to map the LED1[PA4]? To make it turn on?
Thanks.
See the description of GPDO register. It's 32bit register which contains four bits to control four pins.
So, GPDO[0] covers GPIOs 0-3. GPDO[1] covers GPIOs 4-7 and so on...
To write PA[4], you need to write GPDO[1] using mask SIUL2_GPDO_PDO_4n_MASK.
(Note: this depends on used header file. Sometimes the GPDO is defined as array of 32bit registers like this, sometimes it's defined as array of 8bit registers, so it is more straightforward. Both options can be used.)
Anyway, if you use SDK, why not to use SDK functions for this? There are functions like PIN_DRV_WritePin, PIN_DRV_SetPins, PIN_DRV_ClearPins, PIN_DRV_TogglePins...
Regards,
Lukas
Thanks!!!
GPDO[1] works! "SIUL2->GPDO[1] ^= SIUL2_GPDO_PDO_4n_MASK;"
I try to use function "PIN_DRV_TogglePins" to replace the mask(which I'm not familiar with), I found it is much easier for me to achieve the same result.
"PINS_DRV_TogglePins(PTA,1<<4);"
Again, Thank you for your help.