How to set a pin as a bi-directional I/O on a CY7C64315 chip?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
anne_4609456
Level 3
Level 3
10 replies posted 25 sign-ins 5 questions asked

I need to use the same pin sometime as input and sometime as output in the same program.

How can I change the pin direction while program runs in a CY7C64315 chip ?

 

 

 

0 Likes
1 Solution
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Anne:
This is simple port bit-banging.
Read the port's drive mode0 register into a variable.
Mask the port so that unaffected bits are not changed.
OR in the desired value for the bit
Write the temp value back to the port.
Repeat for drive mode 1 register

Code is below. I don't have a suitable kit, but this code built without errors.

//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------

#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
int tempreg;
int P1_5_Mask = 0x20; // all for port 1, bit 5
int P1_5DM0_Tx = 0x20;
int P1_5DM0_Rx = 0x00;
int P1_5DM1_Tx = 0x00;
int P1_5DM1_Rx = 0x20;


void main(void)
{
// M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
// Insert your main routine code here.
}
void Rx2Tx(void )
{
tempreg = PRT1DM0; // read value of port1 DM0
tempreg &= ~ P1_5_Mask; // mask value to isolate pin 5
tempreg |= P1_5DM0_Tx; // write value to pin 5
PRT1DM0 = tempreg; // write value back to port1 DM0
// same for balance of port changes
tempreg = PRT1DM1;
tempreg &= ~ P1_5_Mask;
tempreg |= P1_5DM1_Tx;
PRT1DM0 = tempreg;
}
void RT2Rx(void )
{
tempreg = PRT1DM0;
tempreg &= ~ P1_5_Mask;
tempreg |= P1_5DM0_Rx;
PRT1DM1 = tempreg;

tempreg = PRT1DM1;
tempreg &= ~ P1_5_Mask;
tempreg |= P1_5DM1_Rx;
PRT1DM1 = tempreg;
}

.....
I think I have the syntax right, it built with zero errors.
Copy code into your system and give it a try.

Call the functions from your main line C code.
---- Dennis

View solution in original post

6 Replies
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Drive mode is set in two registers PRTxDM0 and PRTxDM1.
You can change these with simple register writes. From the TRM:

DennisS_46_0-1665599233483.png

---- Dennis Seguine (PSoC Applications Engineer)

0 Likes

Hello DennisS_46

Thanks for the information.
I couldn't find that information in the Datasheet.
Could you please send me the file where I can find how to use it?

For example, I want to make pin P.1.5 as input for sometime and then changed it as output.
What data should I write in the registers to make it as input and then as output?

Thanks in advance for your help.

Regards,
Anne

0 Likes
KyTr_1955226
Level 6
Level 6
250 sign-ins 10 likes given 50 solutions authored

What you are looking for is in the Technical Reference Manual (TRM):
https://www.infineon.com/dgdl/Infineon-enCoRe_V_CY7C643xx_enCoRe_V_LV_CY7C604xx_Technical_Reference_...

See Page 53.  It looks like you do not specifically set a GPIO pin to an "Input" or an "Output" as you would on say, a PIC with the TRISx register, but change the drive mode to set the pin configuration you want.

0 Likes
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Anne:
Are you writing your code in C or in assembler?
---- Dennis

0 Likes

I'm writing in C, using PSoCDesigner 5.4 SP1.

0 Likes
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Anne:
This is simple port bit-banging.
Read the port's drive mode0 register into a variable.
Mask the port so that unaffected bits are not changed.
OR in the desired value for the bit
Write the temp value back to the port.
Repeat for drive mode 1 register

Code is below. I don't have a suitable kit, but this code built without errors.

//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------

#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
int tempreg;
int P1_5_Mask = 0x20; // all for port 1, bit 5
int P1_5DM0_Tx = 0x20;
int P1_5DM0_Rx = 0x00;
int P1_5DM1_Tx = 0x00;
int P1_5DM1_Rx = 0x20;


void main(void)
{
// M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
// Insert your main routine code here.
}
void Rx2Tx(void )
{
tempreg = PRT1DM0; // read value of port1 DM0
tempreg &= ~ P1_5_Mask; // mask value to isolate pin 5
tempreg |= P1_5DM0_Tx; // write value to pin 5
PRT1DM0 = tempreg; // write value back to port1 DM0
// same for balance of port changes
tempreg = PRT1DM1;
tempreg &= ~ P1_5_Mask;
tempreg |= P1_5DM1_Tx;
PRT1DM0 = tempreg;
}
void RT2Rx(void )
{
tempreg = PRT1DM0;
tempreg &= ~ P1_5_Mask;
tempreg |= P1_5DM0_Rx;
PRT1DM1 = tempreg;

tempreg = PRT1DM1;
tempreg &= ~ P1_5_Mask;
tempreg |= P1_5DM1_Rx;
PRT1DM1 = tempreg;
}

.....
I think I have the syntax right, it built with zero errors.
Copy code into your system and give it a try.

Call the functions from your main line C code.
---- Dennis