Problem in reading input from gpio pin in frdm-kea128

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

Problem in reading input from gpio pin in frdm-kea128

2,133 Views
tejasr
Contributor I

Hey, I'm new to frdm boards. I'm currently using S32 DS for my programming. I wanted to start using this board and i set up a basic code to test it. I wanted to use port d2(PTD2) as input and port d3(PTD3) as output. But i'm unable to read anything from port d2 (PTD2). I used the onboard led on PTE7 for verification. In debugging mode, the program flow is not entering the if statement even if the voltage there is high(i verified through dmm). Is there any problem with the header file? The code i used is: 

#include "derivative.h" /* include peripheral declarations SSKEAZ128M4 */
#define PTD2 26 //input
#define PTD3 27 //output
#define PTE7 7 //TESTING


int main(void)
{

GPIOA_PDDR &= ~(1<<PTD2);  //Setting PTD2 as input. IS this right?
GPIOA_PIDR &= ~(1<<PTD2);
PORT_PUE0 |= 1<<PTD2;

GPIOA_PDDR |= 1<<PTD3;  //Setting Ptd3 as output
GPIOA_PIDR &= 1<<PTD3;


GPIOB_PDDR |= 1<<PTE7; //Setting PTE7 as output
GPIOB_PIDR &= 1<<PTE7;


for(;;){
GPIOB_PSOR |= 1<<PTE7;
if( (GPIOB_PDIR) & (1<<PTD2)) // Program is not entering the if condition. Jumping directly to else condition
{
GPIOA_PCOR |=1<<PTD3;
}
else{
GPIOA_PSOR |= 1<<PTD3;
}
GPIOB_PCOR |= 1<<PTE7;
}

}

0 Kudos
9 Replies

1,494 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Tejas,

Please notice the PTD2 and PTD3 are used communicate with SBC(MCZ33903CD5EK) on FRDM-KEAZ128 by default.

PTD2 PTD3 FRDM-KEAZ128.png
You can download the FRDM-KEA Quick start package(REV 8) from FRDM-KEAZ128 webpage.
Then please refer the FRDM_KEA128_GPIO in it's folder.(C:\Quick Start Package v8\Code Project Examples and Sample Drivers (Evaluation Grade Only)\FRDM-KEAZ128\Driver Test SW for KEAZ128\Driver Test SW for KEAZ128\FRDM_KEA128_GPIO)

FRDM_KEA128_GPIO.png

Driver Test SW for KEAZ128.png

Best Regards,

Robin

 

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

0 Kudos

1,493 Views
shravansrinivas
Contributor I

I followed the steps you mentioned above.

Problem in multiple conditions in if loop. I suppose it is not reading inputs and it is not entering "if" condition.

Please suggest a solution to use multiple conditions in IF condition.

if(!READ_INPUT(PTE,PTE0) && !READ_INPUT(PTE,PTE1) && !READ_INPUT(PTE,PTE2) && !READ_INPUT(PTE,PTE3) && !READ_INPUT(PTD,PTD4) && !READ_INPUT(PTD,PTD5) )

0 Kudos

1,493 Views
bobpaddock
Senior Contributor III

Transform it to a Boolean Equation to see which line is not doing what is expected:

uint16_t x_u16 = 1U;

x_u16 &= !READ_INPUT(PTE,PTE0) ;
Print x_u16

x_u16 &= !READ_INPUT(PTE,PTE1) ;

Print x_u16

...

if( 0U != x_u16 )
{
Do stuff;
}


An other way is to read in parallel and compare to a fixed constant.

0 Kudos

1,493 Views
shravansrinivas
Contributor I

Thank you that was helpful. I am able to use the if condition with multiple

conditions and also debugging is fine. But when I try to flash it doesn't

seem to accept the input. What could be the problem?

0 Kudos

1,495 Views
mjbcswitzerland
Specialist V

Hi Tejas

if( (GPIOB_PDIR) & (1<<PTD2)) // Program is not entering the if condition. Jumping directly to else condition

This looks like an error.
if( (GPIOA_PDIR) & (1<<PTD2)) // Program is not entering the if condition. Jumping directly to else condition

if probably correct.

I wish the ports in the KEKEA devices had been named as 32 ports (as they are) rather than as confusing 8 bit ones (that the aren't) since it would be some much easier.

I think they did it like this to wean 8-bit users over to this range without frightening them with 32 bit port numbering - but it makes compatibility between KE/KEA and other parts complicated even when they are more or less the same inside....

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html
Kinetis KEA128:
- http://www.utasker.com/kinetis/TRK-KEA128.html
- http://www.utasker.com/kinetis/FRDM-KEAZ128Q80.html
S32 Design Studio: http://www.utasker.com/kinetis/compilers.html#S32

Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M

For better, faster, cheaper product developments consider the uTasker developer's version, professional Kinetis support, one-on-one training and complete fast-track project solutions to set you apart from the herd : http://www.utasker.com/support.html

0 Kudos

1,495 Views
tejasr
Contributor I

Thanks, Mark for pointing the error. I did the necessary changes and ran the program again and still the same issue. The program flow is not entering the if condition. What could be the issue? 

0 Kudos

1,495 Views
mjbcswitzerland
Specialist V

Hi

I don't see a further error so I have attached a binary file that you can copy to your board to show it working:

1. Beware that PTD2 on the FRDM-KEA128Z board is connected to the output of the MCZ33903CD's SPI (U16) so it will be held low. It is best to remove R65 so that it is then connected only to the connector J6-2 (if not removed you need to apply VDD to J6-2 to get the input to change to '1').
2. The program will flash the green LED when PTD2 is '1'. When PTD2 is '0' it will flash it between yellow/red instead.

The code that I use is
_CONFIG_PORT_INPUT(A, KE_PORTD_BIT2, PORT_PS_UP_ENABLE);
for the input's initialisation
and

extern void fnQuickTask2(TTASKTABLE *ptrTaskTable) // polling task (equivalent to while(1))
{
    if (_READ_PORT_MASK(A, KE_PORTD_BIT2) != 0) {
        _SETBITS(B, KE_PORTH_BIT0);
    }
    else {
        _CLEARBITS(B, KE_PORTH_BIT0);
    }
}

to poll the input and set the yellow LED accordingly.

Since you are not using the uTasker project where this is easy to do (the macros handle all the details and differences between chips) you can compare your code with the code that the macros are creating in the case of the KEA128, which is:

GPIOA_PIDR &= ~(KE_PORTD_BIT2);
GPIOA_PDDR &= ~(KE_PORTD_BIT2);
PORT_PUE0 |= KE_PORTD_BIT2;

if (GPIOA_PDIR & (KE_PORTD_BIT2)) {
    FGPIOB_PSOR = KE_PORTH_BIT0;
}
else {
    FGPIOB_PCOR = KE_PORTH_BIT0;
}

On the OpenDA VCOM there is a command line interface (115'200Baud) which has some menus. In the I/O menu (3) there is a memory debugger so that you can also read registers in case that helps you find a difference.

My feeling is however that you may be making a measurement error and your PTD2 is being held at '0' by the other chip on the board.

Regards

Mark

P.S. You can get a complete FRDM-KEA128 solution at the uTasker OpenSource project, including S32 project and KEA128 simulation - http://www.utasker.com/kinetis/FRDM-KEAZ128Q80.html

uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)
Kinetis: http://www.utasker.com/kinetis.html

0 Kudos

1,495 Views
tejasr
Contributor I

Hi Mark,

You mentioned that I might be making a mistake in measurement and that PTD2 is being held at 0 by some other chip on board. I don't follow that. Can you please elaborate? Also, the same issue is present when I use any other pin as GPIO and configure them as input. The flow is not entering the if condition. It is almost like they are not configured for input. I feel like I'm making a basic mistake somewhere. Can you attach links to some tutorials for S32 DS on FRDM-KEA?

Also, I did go through the utasker project and I want to give it a shot. I found the help on µTasker Kinetis Compiler Information to import utasker project into S32 DS and in step2 it asked me to copy project settings from \Applications\uTaskerV1.4\S32DesignStudio\Project_Settings to the root directory. The problem is I can't find any utasker builds that contain S32DesignStudio in the uTaskerV1.4 folder.

Since I'm just getting into these kinds of boards and projects, I need help. Hope I'm not bugging you!

.

0 Kudos

1,495 Views
mjbcswitzerland
Specialist V

Hi

The open source project version didn't have the S32 project in it so I just added it. If you pull this check-in you will then have an S32 Design Studio project.

Robin has highlighted the possible HW difficulty but if you say you have the same issue with all inputs it will presumably be SW - although I didn't spot it in your code.

Regards

Mark

0 Kudos