i have a developed a program on interrupt of getting a character ahead of one on hyperterminal (eg: a gives me b, b gives me c etc. ) now i have to develop a programin which i store my name and print it unil \n function is used.i was told to use a put str

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

cross mob
Rach_4524011
Level 2
Level 2

i have a developed a program on interrupt of getting a character ahead of one on hyperterminal (eg: a gives me b, b gives me c etc. ) now i have to develop a programin which i store my name and print it unil \n function is used.i was told to use a put string function and then proceed again.. but i m very new to programming and i have to submit my project in less than 2 days.. please help what to add and where. ?

sharing the program with you all.. please help me??IMG_20200417_133321 (2).jpg

0 Likes
1 Solution
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

This is my solution without using interrupts.

#include "project.h"

int main(void) {

    CyGlobalIntEnable; /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    UART_CMD_Start();

    for (;;) {

        uint32 ch = UART_CMD_UartGetChar();

        if (ch == 0) continue;  // No character gotten.

        if (ch != '\n') {

            UART_CMD_UartPutChar(ch + 1);

        } else {

            UART_CMD_UartPutString("\r\n");

            break;

        }

    }

    for (;;) {

        /* Place your application code here. */

    }

}

Get a character in the variable ch and put an incremented code character (ch + 1)  There is no need to use the interrupt.

Please let me know why are you going to use interrupts for this application.

Regards,

Noriaki

View solution in original post

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

Hi,

Then a simple sample using interrupt.

(I'm using CY8CKIT-044)

schematic

001-schematic.JPG

pins

002-pins.JPG

Tera Term log

uart_isr_test_200421.JPG

main.c

==================

#include "project.h"

#define EOL     '\n'

#define CR      '\r'

#define STR_LEN 64

char    str[STR_LEN+1] ; /* 1 for NULL */

volatile int rx_index = 0 ;

volatile int str_received = 0 ;

CY_ISR(rx_isr)

{

    UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY) ;

    if (str_received) { /* previous str has not been taken care of */

        return ;

    }

    if (UART_SpiUartGetRxBufferSize()) { /* something in the buffer */

        str[rx_index] = UART_UartGetByte() ;

        if ((str[rx_index] == EOL)||(str[rx_index] == CR)) { /* end of line detected */

            str[rx_index] = 0 ;

            rx_index = 0 ;

            str_received = 1 ;

            return ;

        }

        rx_index++ ;

        if (rx_index >= STR_LEN) { /* str buffer over flow */

            str[STR_LEN] = 0 ;

            rx_index = 0 ;

            str_received = -1 ;

            return ;

        }

    }      

}

void prompt(void)

{

    UART_UartPutString("> ") ;

}

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    isr_1_ClearPending() ;

    isr_1_StartEx(rx_isr) ;

   

    UART_Start() ;

    prompt() ;

    for(;;)

    {

        if (str_received) {

            UART_UartPutString(str) ;

            UART_UartPutString("\n\r") ;

            prompt() ;

            str_received = 0 ;

        } 

    }

}

==================

moto

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

And if you have used my tty_utils library, it would have been like below.

(Although may not be good for an assignment.)

main.c

===================

#include "project.h"

#include "tty_utils.h"

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    tty_init() ;

  

    prompt() ;

    for(;;) {

        if (get_line()) { // got a line

            print(str) ;

            print("\n") ;

            prompt() ;

        }

    }

}

===================

Tera Term log

010-TeraTerm-log.JPG

schematic

011-schematic.JPG

pins

012-pins.JPG

moto

0 Likes
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

This is my solution without using interrupts.

#include "project.h"

int main(void) {

    CyGlobalIntEnable; /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    UART_CMD_Start();

    for (;;) {

        uint32 ch = UART_CMD_UartGetChar();

        if (ch == 0) continue;  // No character gotten.

        if (ch != '\n') {

            UART_CMD_UartPutChar(ch + 1);

        } else {

            UART_CMD_UartPutString("\r\n");

            break;

        }

    }

    for (;;) {

        /* Place your application code here. */

    }

}

Get a character in the variable ch and put an incremented code character (ch + 1)  There is no need to use the interrupt.

Please let me know why are you going to use interrupts for this application.

Regards,

Noriaki

0 Likes