KL25Z Keil: Determine Memory Address of Ports

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KL25Z Keil: Determine Memory Address of Ports

Jump to solution
2,453 Views
jameshayek
Contributor II

Hello,

     I am very new to the platform and taking a class with the Microcontroler listed above. Please forgive my simple questions.

I am looking to control the on-board LED's with a pushbutton wired into a solder less breadboard. I know I must enable the clock on a pin, set it as input or output, then write to it. Yet not sure how.

In some sample code I see:

SIM_SCGC5   EQU  0x40048038 ;SIM_SCGC5 address        The control for each ports Clock Gate

I belive this controls the clocks for all pins...

and

PORTB_PCR18 EQU  0x4004A000 + 4 * 18 ;PORTB_PCR18 address LED Pin for RED

And this should enable B18 to be used.

I want to enable other ports such as PORTB_PCR19 and PORTD_PCR1 but not sure where the address is in memory.

I am assuming PORTx_PCRn is the naming convention for the register at the location 0x4004A000 + 4*18 and the code EQU equated the name with the location.

Yet I can not figure out where to find the memory locations of the other pins. Any advice?

Where can I find this information?

Tags (2)
0 Kudos
Reply
1 Solution
1,877 Views
jeremyzhou
NXP Employee
NXP Employee

Hi James,

Thank you very much for your focus on Freescale Kinetis product. I'm glad to provide service for you.

You can find the address of all the PORT registers in the section Memory map and register definition in the KL25's reference manual.

Wish it helps.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
6 Replies
1,877 Views
mjbcswitzerland
Specialist V

Hi

Take a look at http://www.utasker.com/kinetis/FRDM-KL25Z.html

To configure a port as input it uses

_CONFIG_PORT_INPUT(B, PORTB_BIT10, PORT_PS_UP_ENABLE);

or as output

_CONFIG_PORT_OUTPUT(B, PORTB_BIT10, (PORT_SRE_SLOW | PORT_DSE_HIGH));

(all details of the clocking etc. are automated)

It includes a KL25 Keil configuration and allows you to simulate the device and the board - this allows you to study the registers and operation for learning purposes and later develop projects much more efficiently than using traditional techniques (of course checking the register details in the user's manual helps too).

To change a bit to '1' or '0' you can then use

_SETBITS(B, PORTB_BIT10);

_CLEARBITS(B, PORTB_BIT10);

To toggle ths state:

_TOGGLE_PORT(B, PORTB_BIT10);

and various other variations.

To read the state of an input pin:

_READ_PORT_MASK(B, PORTB_BIT10);

Regards

Mark

Kinetis: µTasker Kinetis support

K25: µTasker Kinetis FRDM-KL25Z support  / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market


0 Kudos
Reply
1,878 Views
jeremyzhou
NXP Employee
NXP Employee

Hi James,

Thank you very much for your focus on Freescale Kinetis product. I'm glad to provide service for you.

You can find the address of all the PORT registers in the section Memory map and register definition in the KL25's reference manual.

Wish it helps.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,877 Views
jameshayek
Contributor II

Thank you for helping me locate the information.

This was found in the document: KL25P80M48SF0RM in section 11.5 Like you said, in the section titled Memory map and register definition.

For others that may read this. You must call the memory address to the pin like so:

PORTB_PCR19 EQU  0x4004A04C ;PORTB_PCR19 address     

LED Pin for GREEN

Notice the manual shows: 4004_A04C Pin Control Register n (PORTB_PCR19)

You must remove the underscore when writing the above code equating the PORT to the memory address.

If I may ask, why is the underscore shown in the manual and why must we remove it in the code?

1,877 Views
jeremyzhou
NXP Employee
NXP Employee

Hi James,

In fact, I'm also not very clear why the address contain a underscore in the reference manual.

I think it's just a kind of write format and I hope you will not feel confused any more.

Actually, when you create a project for KL25, you needn't to know the address if you want to handle the specific register, just calls the name of the register.

So I highly recommend you to download the sample code of the FRDM-KL25Z and you'll learn the way to handle the specific register.
Hope it helps.

The link of the KL25's sample code package:

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FRDM-KL25Z&fpsp=1&tab=Design_Tools_Ta...
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,877 Views
jameshayek
Contributor II

I downloaded the file FRDM-KL25Z and TWRKL25Z48M Sample Code Package and unpacked it using WinRAR

I only see coding in C. I should of mentioned this before, the class is programming with assembly. We're not allowed to program in C. Not yet at least.

0 Kudos
Reply
1,877 Views
jeremyzhou
NXP Employee
NXP Employee

Hi James,

Yes It's necessary to check the address of registers careful before you handle them.

Any way, if you have some questions about the Kinetis MCU, please just feel free to create a thread in the community and we will follow it.
Have a great day.

Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply