2 Replies Latest reply on Nov 23, 2016 9:57 PM by user_13463998

    PDL 2.1 FM0-64L-S6E1C3 scanf never returns

    user_13463998

      Hi,

         

      I've been writing some demo programs 
      for FM0-64L-S6E1C3 with PDL 2.1.0 and PSoC Creator 4.0.

         

      So far, I could manage SPI(CSIO) and I2C to work.
      Using utilities/printf_scanf by setting following in pdl_user.h
      ===========
      // Printf/Scanf via UART function
      #define PDL_UTILITY_ENABLE_UART_PRINTF              PDL_ON
      #define PDL_UTILITY_ENABLE_UART_SCANF               PDL_ON 
      ===========

         

      Although printf seems reasonably working,
      scanf does not come back.

         

      So I spent a few days and found that 
      int _read(int file, char *ptr, int len) in uart_io.c 
      does not return until it reads "len" number of letters.
      In my debugger, the len was 1024, when I was trying to read a few letters.

         

      So I replaced following lines

         

      ==============
          int i;
          file = file;
          for(i = 0; i < len; i++)
          {
              while (TRUE != Mfs_Uart_GetStatus(UartCh, UartRxFull))
              {
                  /* Wait until there is a character in the Rx FIFO */
              }
              *ptr++ = (char)Mfs_Uart_ReceiveData(UartCh);
          }
          return len;
      ==============

         

      with following lines

         

      ==============
          int i = 0  ;
          char c ;
          file = file ;

         

          while(i < len) {
              while (TRUE != Mfs_Uart_GetStatus(UartCh, UartRxFull)) {
                  /* Wait until there is a characer in the Rx FIFO */
              }
              c = (char)Mfs_Uart_ReceiveData(UartCh);
              Mfs_Uart_ClrStatus(UartCh, UartRxFull) ;
              ptr[i++] = c ;
              if (!isprint(c)) { 
                  break ;
              }
          }

         

          ptr[i] = 0 ;
          return i ;
      ==============

         

      now scanf can read "%d", "%x", "%s".
      But I wonder if my correction is correct,
      or if there is/(will be) a better fix of PDL.

         

      moto