- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi team,
How to get value in TeraTerm after button press in PSOC 5LP.
See my project in the attachment.
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
> I am not able to get the output in teraterm when i press PSOC switch. I am using above code and same project.
The sample I posted are working, although they have their share of problem.
First of all the reason you do not see output in Tera Term is probably because you "CHANGED" the pin assignment.
(Or you did not assign pins)
So now Rx_2 is P0[0] an Tx_2 is P4[7], you could change them to same with your previously "working" projects.
To respect your change I needed to change the connection between the USB-Serial Converter and CY8CKIT-050
Then the Tera Term output of my first main.c was
The problem sneaked in, when you did
i=~OUTPUT_LED_Read() ;
As OUTPUT_LED_Read() returns 0 or 1
the value of uint8 i was
~(0) -> 0xFF
~(1) -> 0xFE
To avoid this I changed the main.c as below
===================
#include "project.h"
uint8 i;
CY_ISR(INPUT_PIN_SW2_Handler)
{
if (OUTPUT_LED_Read() == 0) {
i = 1 ;
} else {
i = 0 ;
}
OUTPUT_LED_Write(i);
UART_PutChar(i + '0'); // 0 or 1 is not printable, adding '0' make it to '0' or '1' which is printable
INPUT_PIN_SW2_ClearInterrupt();
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
PIN_SW2_int_StartEx(INPUT_PIN_SW2_Handler);
UART_Start() ;
UART_PutString("Test A2\n\r") ;
for(;;)
{
// UART_PutString("Test"); // this line will flood your terminal.
//LED_Write(~BUTTON_LED_Read());
}
}
===================
Now the Tera Term Output was
Similarly I changed the second main.c as
====================
#include "project.h"
volatile uint8_t i ;
volatile int button_pressed = 0 ;
CY_ISR(INPUT_PIN_SW2_Handler)
{
if (OUTPUT_LED_Read() == 0) {
i = 1 ;
} else {
i = 0 ;
}
OUTPUT_LED_Write(i);
button_pressed = 1 ;
INPUT_PIN_SW2_ClearInterrupt();
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
PIN_SW2_int_StartEx(INPUT_PIN_SW2_Handler);
UART_Start() ;
UART_PutString("Test B2\n\r") ;
for(;;)
{
if (button_pressed) {
UART_PutChar( i + '0' ) ;
button_pressed = 0 ;
}
}
}
====================
The Tera Term output was
Attached is the project with fixed 2nd main.c, the tx_2 and rx_2 pins are still not locked though.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
First of all, it's not recommended to call time consuming functions such as UART_PutChar(), UART_PutString() in an ISR.
But if you MUST do it, I would modify your main.c as follows
===============================
#include "project.h"
uint8 i;
CY_ISR(INPUT_PIN_SW2_Handler)
{
i=~OUTPUT_LED_Read();
OUTPUT_LED_Write(i);
UART_PutChar(i + '0'); // 0 or 1 is not printable, adding '0' make it to '0' or '1' which is printable
INPUT_PIN_SW2_ClearInterrupt();
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
PIN_SW2_int_StartEx(INPUT_PIN_SW2_Handler);
UART_Start() ;
UART_PutString("Test\n\r") ;
for(;;)
{
// UART_PutString("Test"); // this line will flood your terminal.
//LED_Write(~BUTTON_LED_Read());
}
}
===============================
Or slightly more gracefully
===============================
#include "project.h"
volatile uint8_t i ;
volatile int button_pressed = 0 ;
CY_ISR(INPUT_PIN_SW2_Handler)
{
i = ~OUTPUT_LED_Read();
OUTPUT_LED_Write(i);
button_pressed = 1 ;
INPUT_PIN_SW2_ClearInterrupt();
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
PIN_SW2_int_StartEx(INPUT_PIN_SW2_Handler);
UART_Start() ;
UART_PutString("Test\n\r") ;
for(;;)
{
if (button_pressed) {
UART_PutChar( i + '0' ) ;
button_pressed = 0 ;
}
}
}
===============================
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am not able to get the output in teraterm when i press PSOC switch. I am using above code and same project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
> I am not able to get the output in teraterm when i press PSOC switch. I am using above code and same project.
The sample I posted are working, although they have their share of problem.
First of all the reason you do not see output in Tera Term is probably because you "CHANGED" the pin assignment.
(Or you did not assign pins)
So now Rx_2 is P0[0] an Tx_2 is P4[7], you could change them to same with your previously "working" projects.
To respect your change I needed to change the connection between the USB-Serial Converter and CY8CKIT-050
Then the Tera Term output of my first main.c was
The problem sneaked in, when you did
i=~OUTPUT_LED_Read() ;
As OUTPUT_LED_Read() returns 0 or 1
the value of uint8 i was
~(0) -> 0xFF
~(1) -> 0xFE
To avoid this I changed the main.c as below
===================
#include "project.h"
uint8 i;
CY_ISR(INPUT_PIN_SW2_Handler)
{
if (OUTPUT_LED_Read() == 0) {
i = 1 ;
} else {
i = 0 ;
}
OUTPUT_LED_Write(i);
UART_PutChar(i + '0'); // 0 or 1 is not printable, adding '0' make it to '0' or '1' which is printable
INPUT_PIN_SW2_ClearInterrupt();
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
PIN_SW2_int_StartEx(INPUT_PIN_SW2_Handler);
UART_Start() ;
UART_PutString("Test A2\n\r") ;
for(;;)
{
// UART_PutString("Test"); // this line will flood your terminal.
//LED_Write(~BUTTON_LED_Read());
}
}
===================
Now the Tera Term Output was
Similarly I changed the second main.c as
====================
#include "project.h"
volatile uint8_t i ;
volatile int button_pressed = 0 ;
CY_ISR(INPUT_PIN_SW2_Handler)
{
if (OUTPUT_LED_Read() == 0) {
i = 1 ;
} else {
i = 0 ;
}
OUTPUT_LED_Write(i);
button_pressed = 1 ;
INPUT_PIN_SW2_ClearInterrupt();
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
PIN_SW2_int_StartEx(INPUT_PIN_SW2_Handler);
UART_Start() ;
UART_PutString("Test B2\n\r") ;
for(;;)
{
if (button_pressed) {
UART_PutChar( i + '0' ) ;
button_pressed = 0 ;
}
}
}
====================
The Tera Term output was
Attached is the project with fixed 2nd main.c, the tx_2 and rx_2 pins are still not locked though.
moto