4 Replies Latest reply on Oct 25, 2020 9:10 AM by alli_264371

    SCB UART interrupt works in the old project, but does not work in others even if the whole program is same

    alli_264371
      For the test, I wrote a program that waits for one byte from RX and, after receiving it, sends a string to TX.
      Several years ago I used the same interrupt and if I take that old project(DMX_Button), then everything works.
      But I need to add UART to another project, and even if I open a new virgin project and copy the modules and the main.c file into it, the interrupt does not work.
      What the difference, what wrong in the new project?

        • 1. Re: SCB UART interrupt works in the old project, but does not work in others even if the whole program is same
          MoTa_728816

          Hi,

           

          I read your project.

          First of all, I was surprised that it was working before!

           

          As the MCU is CY8C4245AXI-483,

          I tested it with my CY8CKIT-042.

           

          Since I soldered KitProg's UART with P0[4] and P0[5],

          I connected an external USB-Serial converter to P4[0] and P4[1].

          You may be able to jumper P4[0] and P4[1] to KitProg's P12[7], P12[6].

           

          Anyway, with the modification below, I could get interrupts.

          001-TeraTerm-log.JPG

           

          I modified your project as below.

           

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

          #include <project.h>

           

          volatile char Worbuff[128]={0};

          unsigned char RXBytcount;

          CY_ISR_PROTO (RXinterrupt);

          CY_ISR (RXinterrupt)   

          {

              Worbuff[RXBytcount]=UART_RX_FIFO_RD_REG;

              RXBytcount=1;

           

              UART_SpiUartClearRxBuffer();

              UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);

              RXINT_ClearPending();

              RXINT_Disable() ; // Stop interrupts till it will be released again

          }

           

          int main(void)

          {

              uint8 temp,temp1;

              char num[6]={0};

             

              unsigned int Prevpoint,tempint;

              unsigned char temp4,shiftcount[1];

              unsigned long temp3;

            

              UART_Start();

          //    UART_Init(); //  (1)

          //    UART_Enable(); // (1)

              RXINT_StartEx(RXinterrupt);

              CyGlobalIntEnable; /* Enable global interrupts. */

              RXBytcount=0;

             

              while(1)

              {

                 // CyDelay(5);

                  if(RXBytcount)

                  {  

          //            RXINT_Stop(); // (2)

                      UART_UartPutString("12345");

                      //UART_UartPutChar(Worbuff[0]);

                      UART_UartPutChar(0x0D);

          //            UART_SpiUartClearRxBuffer(); //  (3)

          //            UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY); // (3)

          //            RXINT_ClearPending(); // (3)

                      RXBytcount=0;

          //            RXINT_Start(); // (4)

                      RXINT_Enable() ;

                  }

              }

          }

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

          (1) This is done in UART_Start()

          (2) This should be done in ISR and this should be RXINT_Disable()

          (3) We don't need this

          (4) This should be RXINT_Enable()

           

          It would be nice if you can also refer to my sample of UART usage.

          Re: tty_utils a utility sample for CLI type program

           

          moto

          1 of 1 people found this helpful
          • 2. Re: SCB UART interrupt works in the old project, but does not work in others even if the whole program is same
            alli_264371

            Thanks.

            I suffered for two days and looked for why the interrupt works, but in the main loop the RXBytcount is not met true ..Now It passed, it was necessary to change unsigned char RXBytcount; to volatile unsigned char RXBytcount.

            • 3. Re: SCB UART interrupt works in the old project, but does not work in others even if the whole program is same
              MoTa_728816

              Dear Alli-san,

               

              > Now It passed, it was necessary to change unsigned char RXBytcount; to volatile unsigned char RXBytcount.

              That's right!

              I overlooked it, too.

              A variable which is supposed to be modified in an ISR should be defined as "volatile".

              But at least, my modification was working in my side of the planet, which makes me wonder why.

               

              By the way, since you have a large buffer, you may not have to disable interrupt in the ISR every time.

               

              In my tty_utils sample, I wrote my isr like below.

              By doing "rx_write_index = (rx_write_index + 1) % RX_BUF_LEN", I made the rx_buf[] a ring buffer.

              So unless incoming data exceeds the handling of rx_buf[], there is no need to disable/enable interrupt(s).

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

              CY_ISR(tty_rx_isr)

              {

                  if (UART_GetRxBufferSize()) {

                      rx_buf[rx_write_index] = UART_GetByte() ;

                      rx_write_index = (rx_write_index + 1) % RX_BUF_LEN ;

                  }

                  tty_rx_int_ClearPending() ;

              }

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

               

              And in my main(), I call either get_string() or get_line()

              these functions return 1 when

              (1) found a delimiter in the incoming buffer (get_string())

              (2) found a new line ('\r' or '\n') in the incoming buffer (get_line())

              Otherwise they copy a new coming letter into string work buffer str[].

              So when they returns 1, main program can safely assume that there is a string in the str[] with NULL terminator at the last position.

              Re: tty_utils a utility sample for CLI type program

               

              Or if you don't want to use interrupts and want to use polling method,

              I posted a sample with out using interrupts.

              A simple UART sample without using interrupt for CY8CKIT-044

               

              Anyway, I'm glad that your program started working.

               

              Best Regards,

              25-Oct-2020

              Motoo Tanaka

               

              • 4. Re: SCB UART interrupt works in the old project, but does not work in others even if the whole program is same
                alli_264371

                Thanks, really I remove the interrupt disable in the ISR ,now it look

                 

                CY_ISR (RXinterrupt)  

                {

                    Worbuff[RXBytcount]=UART_RX_FIFO_RD_REG;

                    RXBytcount++;

                    UART_SpiUartClearRxBuffer();

                    UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);

                    RXINT_ClearPending();

                }

                And the main prog

                    while(1)

                    {

                        temp=RXBytcount;

                        CyDelay(200);

                        if((temp)&&(temp==RXBytcount))

                        {  

                            for(temp=0;temp<(RXBytcount-1);temp++)

                            {

                                UART1_PutChar(Worbuff[temp]);

                            }

                            RXBytcount=0;

                            RXINT_Enable();

                        }

                    }

                }

                 

                And work nicely. I using the telegram messenger to communicate with the device from any point in the world...
                and now it sends the strings back

                Screenshot_20201025-175811_Telegram.jpg