Hello all!
I just bought the FRDM-KL25Z Board and trying to do some basic IO-stuff. I use MCUXpresso/Eclipse IDE.
Now I´m wondering, how to enable the Pull-Up resistors. Here´s my code (L. 39-41), but unfortunately the Input-Pin is floating, so no Pullup seem to be activated...
Furthermore, I had to comment out L.44 and L.47, because the compiler threw errors ('kPORT_UnLockRegister' undeclared), even if it was the example from the SDK reference.
Anyone have an idea how to activate the Pullups?
#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_port.h"
#include "fsl_gpio.h"
static void delay(volatile uint32_t nof) {
while(nof!=0) {
__asm("NOP");
nof--;
}
}
int main(void) {
// Init Board-Hardware
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
CLOCK_EnableClock(kCLOCK_PortB);
CLOCK_EnableClock(kCLOCK_PortE);
PORT_SetPinMux(PORTB, 18u, kPORT_MuxAsGpio); // Red LED is on Port PTB18
PORT_SetPinMux(PORTE, 3u, kPORT_MuxAsGpio); // Switch (Drahtbruecke) is on Port PTE3
static const gpio_pin_config_t LED_configOutput = {
kGPIO_DigitalOutput,
1,
};
static const gpio_pin_config_t switch_configInput = {
kGPIO_DigitalInput,
0,
};
GPIO_PinInit(GPIOB, 18u, &LED_configOutput);
GPIO_PinInit(GPIOE, 3u, &switch_configInput);
// Pullups - Not working
port_pin_config_t pinConfig = {
kPORT_PullUp,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
//kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_MuxAsGpio,
//kPORT_UnLockRegister,
};
PORT_SetPinConfig(PORTE, 3u, &pinConfig);
while(1) {
if((((GPIOE->PDIR) >> 3) & 0b1) == 0) {
GPIO_ClearPinsOutput(GPIOB, 1<<18);
delay(2000000);
GPIO_SetPinsOutput(GPIOB, 1<<18);
delay(1200000);
}
}
return 0;
}
Jan
From user's manual:
Here I made a mistake since i looked at the enable control line, whereas they are in fact disabled out of reset.
From Data sheet:
Therefore enabling them should give you 20..50k pull-up strength.
Since I don't use SDK I don't know whether it has an error or you are using it incorrectly, but this can be checked by reading back the PORTE_PCR3 register to check that it has 0x3 at the end (pull-up selected ad enabled).
Regards
Mark
I wasn´t motivated anymore on fiddling around with the SDK-functions, so I directly write to the register now to enable the Pullups. If anyone is interested, here´s my code:
uint32_t volatile * const address_PORTE_PCR3 = (uint32_t *) 0x4004D00C; //Datasheet p.181 (Address of PORTE_PCR3)
*address_PORTE_PCR3 = ((*address_PORTE_PCR3) | 0b00000000000000000000000000000011); // Datasheet p.185
Thanks Mark for your help too!
Hi
PTE3 is pulled up "out of reset" so maybe you are incorrectly measuring it (?)
Try also the open source uTasker project for the KL25 in order to kick start your work (including KL25 simulation to slash development and testing time).
uTasker code to do what you do is much more efficient:
#define FRDM_KL25Z // define the board / prozessor to run on
#define USE_MAINTENANCE // enable debug interface on UART
#define USE_USB_CDC // enable debug interface also on USB-CDC
#include "config.h" // include all necessary headers
#define INPUT_SWITCH PORTE_BIT3
#define RED_LED PORTB_BIT18
extern void fnApplication(TTASKTABLE *ptrTaskTable)
{
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(B, (RED_LED), (RED_LED), (PORT_SRE_SLOW | PORT_DSE_HIGH)); // red LED on PTB18 - clocked, configured, drives '1''
_CONFIG_PORT_INPUT(E, (INPUT_SWITCH), PORT_PS_UP_ENABLE); // PTE3 clocked, configured as input with pull-up enabled
FOREVER_LOOP() {
if ((_READ_PORT_MASK(E, INPUT_SWITCH) == 0)) {
_CLEARBITS(B, RED_LED); // set low
fnDelayLoop(20000); // accurate 20000us delay
_SETBITS(B, RED_LED); // set high
fnDelayLoop(20000); // accurate 20000us delay
}
}
}
Regards
Mark
Complete Kinetis solutions for professional needs, training and support: http://www.utasker.com/kinetis.html
Kinetis KL25, KL26, KL27, KL28, KL43, KL46, KL82
- http://http://www.utasker.com/kinetis/FRDM-KL25Z.html
- http://www.utasker.com/kinetis/TWR-KL25Z48M.html
- http://www.utasker.com/kinetis/FRDM-KL26Z.html
- http://www.utasker.com/kinetis/TEENSY_LC.html
- http://www.utasker.com/kinetis/FRDM-KL27Z.html
- http://www.utasker.com/kinetis/Capuccino-KL27.html
- http://www.utasker.com/kinetis/FRDM-KL28Z.html
- http://www.utasker.com/kinetis/FRDM-KL43Z.html
- http://www.utasker.com/kinetis/TWR-KL43Z48M.html
- http://www.utasker.com/kinetis/FRDM-KL46Z.html
- http://www.utasker.com/kinetis/TWR-KL46Z48M.html
- http://www.utasker.com/kinetis/FRDM-KL82Z.html
uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market
Request Free emergency remote desk-top consulting at http://www.utasker.com/services.html
Open Source version at https://github.com/uTasker/uTasker-Kinetis
Thanks for the answer!
The uTasker project looks interesting, but atm I´m still learning how to use the KL25Z in general, and so I want to use the default stuff with minimal overhead. (Later that is too stressful and I´ll switch to uTasker ;-) ).
So in general, my code for the Pullup-activation is correct??
PTE3 is pulled up "out of reset"
What do you mean exactly by that? Normally (e.g. on AVRs or PICs 8-bit MCUs) the Pullup is activated, and than constantly connects the PIN and VCC/GND with that resistor. Here not?
Jan
I mean that the default is to have the pull-up connected between the input pin and +3V3 so even if you have no code to select the pull-up it will already be connected.
Regards
Mark
Hey Mark! I didn´t quite understand your answer. The thing is, when I execute the code, a certain behaviour starts. The program flashes a LED when a certain Pin is LOW. But here the LED sometimes flashes, sometimes not. So the electric field at the Input-Pin is enough to let the MOSFET switch to the other state. With an attached 56kOhm Pullup at the Input-Pin, everything is stable.
So I´m rather sure, that the Pull-Ups aren´t activated. How would be the SDK-Code do I enable them?
Thanks!