1 Reply Latest reply on Feb 5, 2012 1:14 AM by user_1377889

    flag processing in main not work but in ISR yes!!!!

    alessandro.buffa

      HI my problem is this:

      i set a flag (CmdCpuFlag) inside an ISR of uart. on the main inside while(1) ceck the status by CeckCmdFlag() of this flag and if is ==1 send one char on uart.

      IF I WRITE CeckCmdFlag() INSIDE THE ISR (UartData_C) WORKING.
      IF I WIRTE CeckCmdFlag() INSIDE THE WHILE(1) (UartData_C) NOT WORKING. !!!

      WHY????? I SET THE FLAG AND INSIDE WHILE(1) CECK IF THIS FLAG IS SETTED send char and reset the flag to 0... NOTHING MORE!!!


      #include <m8c.h> // part specific constants and macros
      #include "PSoCAPI.h" // PSoC API definitions for all User Modules
      #include <stdlib.h>
      #include <string.h>

      #pragma interrupt_handler UartData_C

      BYTE comm=0;
      unsigned char CmdCpuBuffer[255];
      char CmdCpuFlag=0;

      void UartData_C(void)
      {
      static char Cmd=0,Count=0,DataCount;
      Cmd=UART_1_cReadChar();
      CmdCpuBuffer[Count]=Cmd;
      if (Count==1)
      {
      DataCount=Cmd+3;
      }

      if (Count>1)
      {
      DataCount--;
      if(DataCount==0)
      {
      CmdCpuFlag=1;
      Count=0;
      }
      }
      Count++;
      UART_1_PutChar(Cmd);

      }


      void main()
      {
      M8C_EnableGInt;
      M8C_EnableIntMask(INT_MSK0,INT_MSK0_GPIO);
      Timer16_1_EnableInt();
      Timer16_1_Start();
      UART_1_CmdReset();
      UART_1_IntCntl(UART_1_ENABLE_RX_INT);
      UART_1_Start(UART_1_PARITY_NONE);

      while(1)
      {
      CeckCmdFlag();
      }
      }



      void CeckCmdFlag(void)
      {
      if(CmdCpuFlag==1)
      {
      UART_1_PutChar(0x09);
      UART_1_PutChar(0x09);
      UART_1_PutChar(0x09);
      CmdCpuFlag=0;
      }
      }