Basic question about GPIO usage in Kinetis devices

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic question about GPIO usage in Kinetis devices

Jump to solution
435 Views
juanm
Contributor III

Hi! I have a very basic question about the use of the GPIO ports in Kinetis devices (I'm using FRDM-KL25Z and CW v10.6).

I have been using a library for an LCD 16x2 display with the HCS08 family, but now I wanted to port it to the KL25Z.

My question is with the following function:

void LCD_send_byte(char address, char data)

{

  unsigned int temp;

  PTBD_PTBD0 = address;               // config the R/S line

  LCD_ENABLE = 0;                 // set LCD enable line to 0

  LCD_send_nibble(data >> 4);     // send the higher nibble

  LCD_send_nibble(data & 0x0f);   // send the lower nibble

  for (temp=1000; temp; temp--);

}

With this line: PTBD_PTBD0 = address; I assign the value of "address" to PTB0, but the question is, how can I implement that line in Kinetis? I tried the following:


GPIOB_PDOR = (address<<0); but that didn't work.


That's it, and sorry if this is a simple question.

Thanks.

0 Kudos
1 Solution
166 Views
mjbcswitzerland
Specialist V

Hi

As long as address is equal to the bit (0x00100000 for PTB20) it will be OK for any single port bit control.

Otherwise, if address is just TRUE or FALSE you can do

#define RS_LINE 0x00100000

if (address == TRUE) {

    GPIOB_PSOR = RS_LINE; // set to '1'

}

else {

    GPIOB_PCOR = RS_LINE; // clear to '0'

}

The port macros that I use are here: http://www.utasker.com/forum/index.php?topic=1875.0

Regards

Mark

Kinetis: µTasker Kinetis support

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

LCD: http://www.utasker.com/docs/uTasker/uTaskerLCD.PDF

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


View solution in original post

0 Kudos
5 Replies
166 Views
mjbcswitzerland
Specialist V

Hi

GPIOB_PDOR = ((GPIOB_PDOR & ~(address)) | (address)); // assuming address is a single bit controlling the RS line

However also check out: http://www.utasker.com/kinetis/FRDM-KL25Z.html#LCD

This includes a 4/8 bit interface for the FRDM-KL25Z to character displays (1 x 8 to 4 x 40) and simulates the KL25, FRDM-KL25Z and the LCD.

Regards

Mark

Kinetis: µTasker Kinetis support

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

LCD: http://www.utasker.com/docs/uTasker/uTaskerLCD.PDF

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

166 Views
juanm
Contributor III

Thanks! And if I want to do the same but with a different pin? (PTB20)

0 Kudos
167 Views
mjbcswitzerland
Specialist V

Hi

As long as address is equal to the bit (0x00100000 for PTB20) it will be OK for any single port bit control.

Otherwise, if address is just TRUE or FALSE you can do

#define RS_LINE 0x00100000

if (address == TRUE) {

    GPIOB_PSOR = RS_LINE; // set to '1'

}

else {

    GPIOB_PCOR = RS_LINE; // clear to '0'

}

The port macros that I use are here: http://www.utasker.com/forum/index.php?topic=1875.0

Regards

Mark

Kinetis: µTasker Kinetis support

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

LCD: http://www.utasker.com/docs/uTasker/uTaskerLCD.PDF

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


View solution in original post

0 Kudos
166 Views
juanm
Contributor III

That worked! I just thought there would be a more direct way for doing this (like in the S08).

Thanks!!!!!!

0 Kudos
166 Views
mjbcswitzerland
Specialist V

Hi

I don't know what the S08's PTBD_PTBD0 does but the Kinetis has the ability to set, clear or toggle single/multiple pins. What the Kinetis can't do is set of clear single pins based on a variable in a single instruction.

However, even with more instructions it will do it much faster than an S08 with its single one ;-)

Regards

Mark

Kinetis: µTasker Kinetis support

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

LCD: http://www.utasker.com/docs/uTasker/uTaskerLCD.PDF

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

0 Kudos