Below is some sample code I gathered from a friends program that I commented and modified.
So far, I understand why we set up the clocks and how to turn them on. I also understand equating the addresses for the pins being used, weather for a control register or a direction register.
What I don't get is how to set values for the GPIO. I don't understand the section: Initialize GPIO's and setup I/O status in the code below.
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;Memory Address information found in the KL25P80M48SF0RM document |||||||||||||||| ;/////////////////////////////////////////////////////////////////////////////////
SIM_SCGC5 EQU 0x40048038 ;SIM_SCGC5 address The control for each ports Clock Gate PORTB_PCR18 EQU 0x4004A000 + 4 * 18 ;PORTB_PCR18 address LED Pin for RED
;Our added code to the example code found above in the lab manual PORTB_PCR19 EQU 0x4004A04C ;PORTB_PCR19 address LED Pin for GREEN PORTA_PCR13 EQU 0x40049034 ;PORTA_PCR13 address Pin used for button PORTD_PCR1 EQU 0x4004C004 ;PORTD_PCR1 address LED Pin for BLUE
GPIOA_PDDR EQU 0x400FF014 ;GPIOA_PDDR Register Address PDDR is Port Data Direction Register GPIOB_PDDR EQU 0x400FF054 ;GPIOA_PDDR Register Address This sets the pin as input or output GPIOD_PDDR EQU 0x400FF0D4 ;GPIOB_PDDR Register Address GPIOA_PDIR EQU 0x400FF010 ;GPIOA_PDIR Register Address This is the Port Data Input Register
AREA asm_area, CODE, READONLY EXPORT asm_main
asm_main ;assembly entry point for C function, do not delete ; Add program code below here
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;Initialize clock pins ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ;/////////////////////////////////////////////////////////////////////////////////
LDR R0,=SIM_SCGC5 ;Load address of SIM_SCGC5 to R0 LDR R1,[R0] ;Put value of SIM_SCGC5 into R1 LDR R2,=0x00003E00 ;Load value to turn on all port clocks into R2 ORRS R1,R2 ;OR R2 into R1 for use of masking STR R1,[R0] ;Put value back into SIM_SCGC5, ;This puts 0011111000000000, binary of 3E, into the Sim_SCGC5 register ;Which turns on the port clocks A-E. ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;Initialize GPIO's and setup I/O status |||||||||||||||||||||||||||||||||||||||||| ;/////////////////////////////////////////////////////////////////////////////////
LDR R0,=GPIOA_PDDR ;Load address of GPIOA to R0 LDR R1,=0x00000000 ;Load value to R1 <~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! How do we determine this value? !!! STR R1,[R0] ;Put value into GPIOA LDR R0,=GPIOB_PDDR ;Load address of GPIOB to R0 LDR R1,=0x000C0000 ;Load value to R1 <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And this value STR R1,[R0] ;Put value into GPIOB LDR R0,=GPIOD_PDDR ;Load address of GPIOD to R0 LDR R1,=0x00000002 ;Load value to R1 <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And this value STR R1,[R0] ;Put value into GPIOD
Any hints/advice?
解決済! 解決策の投稿を見る。
Hi
Your code is writing
0x00000000 to GPIOA_PDDR
0x000c0000 to GPIOB_PDDR
0x00000002 to GPIOC_PDDR
So Port A is set as all inputs.
Port B has outputs configured on PTB18 and PTB19
and
Port C an output configured on PTC1
The pins configured as outputs will be driving '0'
To write a '1' to PTC1 (for example) you can write 0x2 to GPIOC_PSOR
However it depends on the processor that you are using whether it will work yet because many pins reset to a default peripheral function and not GPIO. Therefore you should also program each pin's multiplex function to GPIO beforehand:
PORTX_PCRn = 0x00000100 (GPIO function)
In asembler:
Regards
Mark
Kinetis: http://www.utasker.com/kinetis.html
KL25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support
For the complete "out-of-the-box" Kinetis experience and faster time to market
Hi
Your code is writing
0x00000000 to GPIOA_PDDR
0x000c0000 to GPIOB_PDDR
0x00000002 to GPIOC_PDDR
So Port A is set as all inputs.
Port B has outputs configured on PTB18 and PTB19
and
Port C an output configured on PTC1
The pins configured as outputs will be driving '0'
To write a '1' to PTC1 (for example) you can write 0x2 to GPIOC_PSOR
However it depends on the processor that you are using whether it will work yet because many pins reset to a default peripheral function and not GPIO. Therefore you should also program each pin's multiplex function to GPIO beforehand:
PORTX_PCRn = 0x00000100 (GPIO function)
In asembler:
Regards
Mark
Kinetis: http://www.utasker.com/kinetis.html
KL25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support
For the complete "out-of-the-box" Kinetis experience and faster time to market