How to get string data after button press in PSOC 5LP

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

cross mob
lock attach
Attachments are accessible only for community members.
abho_4730071
Level 4
Level 4
First like received

Hi team,

How to get value in TeraTerm after button press in PSOC 5LP.

See my project in the attachment.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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)

000-pins.JPG

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

IMG_4459.JPG

Then the Tera Term output of my first main.c was

001-A-output.JPG

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

002-A2-output.JPG

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

004-B2-output.JPG

Attached is the project with fixed 2nd main.c, the tx_2 and rx_2 pins are still not locked though.

moto

View solution in original post

0 Likes
3 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

0 Likes

Hi,

I am not able to get the output in teraterm when i press  PSOC switch. I am using above code and same project.

pastedImage_0.png

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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)

000-pins.JPG

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

IMG_4459.JPG

Then the Tera Term output of my first main.c was

001-A-output.JPG

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

002-A2-output.JPG

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

004-B2-output.JPG

Attached is the project with fixed 2nd main.c, the tx_2 and rx_2 pins are still not locked though.

moto

0 Likes