Hi,
I'm trying to use the RESET_b pin in its ALT1 configuration on the MKL03Z8VFG4, PTA1 GPIO.
I'm using uVision and created the project there. In the startup_MKL03Z4.s file, I see the line:
FOPT EQU 0xBD
To changed the value to
FOPT EQU 0xB5 ; 1011 0101
in order to disable the RESET function.
Then in my main.c, I put:
PORTA_PCR1 = 0x141;
GPIOA_PDDR = 0x2;
GPIOA_PSOR = 0x2;
while(1){
for(int i=0; i<200000; i++){}
GPIOA_PTOR = 0x2; // port A pin 1 toggle
}
I see a little something happening on the pin (like toggling between GND and Hi-Z) but it's not driving an LED. What am I doing wrong?
Thanks!!!
Hi Daniel,
I have found some errors in your code:
1. enable portA clock.
Please add this code before your do PORTA configuration.
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
2. for code have error.
for(int i=0; i<200000; i++){}
int i, the max data is 32767, so if you use for(int i=0; i<200000; i++){}, the code won't execute toggle GPIO.
You can use this code for delay:
unsigned int i,j;
for(i=0;i<10;i++) for(j=0;j<65535;j++);
I have tried to disable the reset function on the PTA1, and the PTA1 can toggle.
After you download the code, please power on your board again, and test the reset pin.
Following code for your reference in main, after modify the FOPT to 0XB5:
SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;
PORTA_PCR1 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
GPIOA_PDDR |= 1<<1;
GPIOA_PSOR |= 1<<1;
while (1)
{
for(i=0;i<10;i++) for(j=0;j<65535;j++);
GPIOA_PTOR |= 1<<1;
}
If you still have question, please let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Jingjing, thank you for your help.
I have been setting the registers by hand, without using the masks, just so I can be sure the bits are doing what I want.
Here is my complete main.c. The code successfully toggles PTA7, but not PTA1. Something must be missing!
#include "system_MKL03Z4.h"
#include "MKL03Z4.h"
int main(){
SystemInit();
SIM_SCGC5 |= 0x200; // port A clock enable (bit 9 set)
PORTA_PCR1 = 0x141; // port A pin 1 is gpio(alt1) (bit 8 set), drive strength high (bit 6 set)
PORTA_PCR7 = 0x141; // port A pin 7 is gpio(alt1) (bit 8 set), drive strength high (bit 6 set)
GPIOA_PDDR |= 0x2; // port A pin 1 is output (bit 1 set)
GPIOA_PDDR |= 0x80; // port A pin 7 is output (bit 7 set)
PORTB_PCR1 = 0x243; // port B pin 1 is lpuarttx(alt2) (bit 9 set), drive strength high (bit 6 set), pullup enable
PORTB_PCR2 = 0x203; // port B pin 1 is lpuartrx(alt2) (bit 9 set), pullup enable
unsigned int j;
while(1){
for(j=0;j<65535;j++){}
GPIOA_PTOR = 0x82; // port A pin 1 and pin 7 toggle
}
return(0);
}
And in my startup_MKL03Z4.s file I have the line:
FOPT EQU 0xB5 ; 1011 0101
I think the code above covers all the register settings you suggested. There must be something missing.
Thanks!
Hi Daniel,
Thank you for your more details.
Your code is correct now.
Please check these points:
1. generate the hex file
Then check 0x40d in the hex file, whether it is 0XD5 which you write?
2. what the IDE you are using?
If you use the IAR, you should add "“--enable_config_write" in the flash loader configuration, otherwise, the IAR will protect 0X400 area, even you write it, the code download to the chip can't be changed.
3. What the debug you are using?
Please download the code to the chip, and test it without debugging it.
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
1. I'm not sure exactly how to read the hex file, but here are the last 3 lines:
:10040000FFFFFFFFFFFFFFFFFFFFFFFFFEB5FFFF47
:040000050000014BAB
:00000001FF
Is that the right section? I see B5 in there near the end.
2. I am using Keil uVision IDE to write the code, compiling to hex, and flashing with KinetisFlashTool over UART. I don't see an option to enable_config_write anywhere in there.
3. No debugger. I load the hex to the chip with KinetisFlashTool, then reboot it (power off/on) to run.
Thanks!
Hi Daniel,
Send me your test project, I would like to help you to check it.
After I found your problem, I will modify it and tell you, after modifcation, I will send it back to you.
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi, a zip file with the project folder is below. Thanks for your help!
http://www.mediafire.com/download/2jalf2j606vpsoh/uvision.zip
Daniel
I figured out a little piece of the puzzle.
When I pull up PTA1 with a resistor, it toggles. Open drain behavior.
From what the datasheet says, it seems like I should make this a push-pull driven output by:
PORTA_PCR1 = 0x143;
Is this not true? If so I have to re-work 100 pcbs :smileyshocked:
Hi Daniel,
In our KL quick reference manual, we recommend customer add 4.7K to 10k external pullup resistor on the RESET_b pin, because the internal pullup is weak.
You can find the KL quick reference manual in this link:
page 23.
If you didn't add the external pullup resistor, you must enable the internal pullup by the code:
PORTA_PCR1 = 0x143;
Otherwise, PTA1 can't toggle, my board also have the external pullup, so PTA1 on my side can toggle.
Please add internal pull by the code, then try again on you side.
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------