how to configure GPIO with positive logic on freescale KL25???

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

how to configure GPIO with positive logic on freescale KL25???

Jump to solution
2,630 Views
sacchettigiampa
Contributor II

with cmd-CPU  -> 0 to REGISTER  GPIO the port value is 3,3 V

with cmd-CPU  -> 1 to REGISTER  GPIO the port value is 0 V (close to ground) negative logic.

What REGISTER which registers manage for positive logic to GPIO???

with cmd-CPU  -> 1 to REGISTER  GPIO the port value is 3,3 V (to VDD)

with cmd-CPU  -> 0 to REGISTER  GPIO the port value is 0 V (close to ground)

best regards

0 Kudos
1 Solution
1,207 Views
perlam_i_au
Senior Contributor I

Sacchetti:

I cannot understand pretty well your inquiry, but below you will find steps to follow in order to configure any Port pin or PTBx to use it as output and send a high or low level for a specific pin, please see below:

  1. Check on Pinout wich pin you want to use, in this case I will use as example PTB18. Pinout.jpg
  2. The first thing you need to do in your code is enable system clock gating for the port you want to use, in this case I will use microcontroller KL25 but you can look for the SIM in which you can enable a specific port, in this case I need to enable clock gating for Port B with this instruction: SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;
  3. On newer microcontrollers each physical pin could have more than one possible function, then you need to choose which function you want to use for your pin, in this case we want to use is as GPIO (General Purpose Input/Output) then you select the ALT option for your pin that corresponds to GPIO. To do it use this instruction: PORTB_PCR18 = PORT_PCR_MUX(1); Pinout.jpg
  4. Next step requires to configure data direction for the specific pin you want to use with the Data Direction register for each data port, in this register if you set a bit of the port this means that bit will be an output, otherwise if you clear a bit on the register that means that bit will be an input. As example I will configure PTB18 as output with this instruction: GPIOB_PDDR |= (1 << 18);
  5. After this configuration you are able to select value of your output pin using four different registers:
    1. Port Data Output Register (GPIOx_PDOR) - If you write GPIOB_PDOR |= (1 << 18); you will get a high level on the pin PTB18, If you write GPIOB_PDOR |= (0 << 18); you will get a low level on the pin PTB18.
    2. Port Set Output Register (GPIOx_PSOR) - If you write GPIOB_PSOR |= (1 << 18); you will get a high level on the pin PTB18,  If you write GPIOB_PSOR |= (0 << 18); anything will happen.
    3. Port Clear Output Register (GPIOx_PCOR) - If you write GPIOB_PCOR |= (1 << 18); you will get a low level on the pin PTB18,  If you write GPIOB_PCOR |= (0 << 18); anything will happen.
    4. Port Toggle Output Register (GPIOx_PTOR) - If you write GPIOB_PTOR |= (1 << 18); you will get a opposite level you have on the pin PTB18,  If you write GPIOB_PTOR |= (0 << 18); anything will happen.

Please let me know if this information is useful.

View solution in original post

0 Kudos
4 Replies
1,207 Views
perlam_i_au
Senior Contributor I

Hi Sacchetti:

I am not pretty sure what you mean with your question but I will guess that you want to know with which register you could write a high logic and get a 0v or ground connection, in this case you can so it using the Port Clear Output Register (GPIOx_PCOR).

Please let me know if this is what you was looking for.


Have a great day,
Perla Moncada

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

0 Kudos
1,207 Views
sacchettigiampa
Contributor II

thanks for your collaboration, it is the first time you use freescale, I would like to know how to drive PTBX to get high (VDD) for driving the NPN transistor, how can I drive TRISTATE PORT ?? Now is LOW (GND) a command TRUE et HIGH (VDD) a command FALSE.

What procedure for configuration PORT  is VALID for this schematic??

Thanks for you patient, best regards

SCHEMATIC APP.jpg

0 Kudos
1,208 Views
perlam_i_au
Senior Contributor I

Sacchetti:

I cannot understand pretty well your inquiry, but below you will find steps to follow in order to configure any Port pin or PTBx to use it as output and send a high or low level for a specific pin, please see below:

  1. Check on Pinout wich pin you want to use, in this case I will use as example PTB18. Pinout.jpg
  2. The first thing you need to do in your code is enable system clock gating for the port you want to use, in this case I will use microcontroller KL25 but you can look for the SIM in which you can enable a specific port, in this case I need to enable clock gating for Port B with this instruction: SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;
  3. On newer microcontrollers each physical pin could have more than one possible function, then you need to choose which function you want to use for your pin, in this case we want to use is as GPIO (General Purpose Input/Output) then you select the ALT option for your pin that corresponds to GPIO. To do it use this instruction: PORTB_PCR18 = PORT_PCR_MUX(1); Pinout.jpg
  4. Next step requires to configure data direction for the specific pin you want to use with the Data Direction register for each data port, in this register if you set a bit of the port this means that bit will be an output, otherwise if you clear a bit on the register that means that bit will be an input. As example I will configure PTB18 as output with this instruction: GPIOB_PDDR |= (1 << 18);
  5. After this configuration you are able to select value of your output pin using four different registers:
    1. Port Data Output Register (GPIOx_PDOR) - If you write GPIOB_PDOR |= (1 << 18); you will get a high level on the pin PTB18, If you write GPIOB_PDOR |= (0 << 18); you will get a low level on the pin PTB18.
    2. Port Set Output Register (GPIOx_PSOR) - If you write GPIOB_PSOR |= (1 << 18); you will get a high level on the pin PTB18,  If you write GPIOB_PSOR |= (0 << 18); anything will happen.
    3. Port Clear Output Register (GPIOx_PCOR) - If you write GPIOB_PCOR |= (1 << 18); you will get a low level on the pin PTB18,  If you write GPIOB_PCOR |= (0 << 18); anything will happen.
    4. Port Toggle Output Register (GPIOx_PTOR) - If you write GPIOB_PTOR |= (1 << 18); you will get a opposite level you have on the pin PTB18,  If you write GPIOB_PTOR |= (0 << 18); anything will happen.

Please let me know if this information is useful.

0 Kudos
1,207 Views
sacchettigiampa
Contributor II

Hi Perla

Thank you very much for your time is really useful, I understand how it works

Best regards

0 Kudos