- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
Solved! Go to Solution.
- Tags:
- bi-directional pin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Drive mode is set in two registers PRTxDM0 and PRTxDM1.
You can change these with simple register writes. From the TRM:
---- Dennis Seguine (PSoC Applications Engineer)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anne:
Are you writing your code in C or in assembler?
---- Dennis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm writing in C, using PSoCDesigner 5.4 SP1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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