I am a newbie in arm programming. I am using teensy 3.2 which has MK20DX256 microcontroller chip and the led is connected to PTC5 of MC.
I have written this code to blink the LED.
The project builds without error but HEX file does not blink led. I am using teensy loader to program the board with HEX file.
Here is my code:
#include "MK20D7.h"
void delay(unsigned int);
int main(void) {
SystemCoreClockUpdate(); /* Get Core Clock Frequency */
SysTick_Config(SystemCoreClock/1000); /* Generate interrupt each 1 ms */
PORTC->PCR[5]= 256; //declared as GPIO
PTC->PDDR=0x00000010;
while(1){
PTC->PDOR=0x00000010;
delay(500);
PTC->PDOR=0x00000000;
delay(500);
}
void delay(unsigned int ms){
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<20000;j++);
}
}
Please help me in finding what is wrong with this code
Try this first see if the led comes on and stays on
# include "MK20D7.h"
int main(void)
{
PORTC->PCR[5]= 256; //declared as GPIO
PTC->PDDR=0x00000010;
PTC->PDOR=0x00000010;
//PTC->PDOR=0x00000000;
while(1) continue;
}
If not then you need to disassemble, see below.
Then try this
# include "MK20D7.h"
int main(void)
{
PORTC->PCR[5]= 256; //declared as GPIO
PTC->PDDR=0x00000010;
//PTC->PDOR=0x00000010;
PTC->PDOR=0x00000000;
while(1) continue;
}
and see if it goes/stays off
Then try this
# include "MK20D7.h"
void delay(unsigned int );
int main(void)
{
PORTC->PCR[5]= 256; //declared as GPIO
PTC->PDDR=0x00000010;
while(1)
{
PTC->PDOR=0x00000010;
delay();
PTC->PDOR=0x00000000;
delay();
}
}
void delay(void)
{
volatile unsigned int j;
for(j=0;j<20000;j++);
}
Assuming you have the right header file and the binary is built and linked properly, etc. Ideally you want to disassemble the binary, examine vector table to insure its placement and proper contents. Examine the code after the main label and compare it to the documentation for the few registers used.
PSOR and PCOR are easier to use
PTC->PSOR=1<<5;
delay();
PTC->PCOR=1<<5;
delay();
User contributions licensed under CC BY-SA 3.0