This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem using the printf-function

Hello,

i am having problems using the printf-function on a XC161CJ. The initialization i used is from an older project with the same controller and was running properly.

In the new projrct everything works fine until the printf, there the program hangs. Only interrupts with higher priority are still served.
Anyone an idea what's the cause for this?

Thanks in advance

Sebastian

Parents
  • Hello Sebastian,

    did you check, when hanging, what about TI flag?
    If you did not set in the initialization before using printf - the program will
    allways wait for this.

    void ASC0_vInit(void)
    {
      // USER CODE BEGIN (Init,2)
    
      // USER CODE END
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the ASC0 Baudrate Generator:
      ///  -----------------------------------------------------------------------
      ///  - fractional divider as prescaler for baud rate timer is used
    
      ASC0_FDV       =  0x00AD;      // load ASC0 fractional divider register
    
      ///  - required baud rate = 38,400 kbaud
      ///  - real baud rate     = 38,397 kbaud
      ///  - deviation          = -0,009 %
    
      ASC0_BG        =  0x000A;      // load ASC0 baud rate time reload register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the ASC0 Operation Mode:
      ///  -----------------------------------------------------------------------
      ///  - 8-bit data asychronous operation with one stop bit
      ///  - receiver is enabled
      ///  - fractional divider is enabled
    
      ASC0_CON       =  0x0811;      // load ASC0 control register
    
      ///  -----------------------------------------------------------------------
      ///  FIFO Configuration:
      ///  -----------------------------------------------------------------------
      ///  - receive FIFO is disabled
      ///  - transmit FIFO is disabled
    
      ASC0_RXFCON    =  0x0102;      // load ASC0 receive FIFO control register
      ASC0_TXFCON    =  0x0102;      // load ASC0 transmit FIFO control register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ASC0 Port Pins:
      ///  -----------------------------------------------------------------------
      ///  - P3.10 is used for ASC Transmit Data Output (TxDA0)
      ///  - P3.11 is used for ASC0 Receive data Input (RxDA0)
    
      ALTSEL0P3     |=  0x0400;      // select alternate output function
      P3   = (P3   & ~(uword)0x0400) | 0x0400;    //set data register
      DP3  = (DP3  & ~(uword)0x0400) | 0x0400;    //set direction register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ASC0 Interrupts:
      ///  -----------------------------------------------------------------------
    
      // USER CODE BEGIN (ASC0_Function,3)
    	ASC0_TIC_IR=1;							// Start KEIL printf()
      // USER CODE END
    
      ASC0_CON      |=  0x8000;      // enable baud rate generator
    
    
    } //  End of function ASC0_vInit
    

    Stefan

Reply
  • Hello Sebastian,

    did you check, when hanging, what about TI flag?
    If you did not set in the initialization before using printf - the program will
    allways wait for this.

    void ASC0_vInit(void)
    {
      // USER CODE BEGIN (Init,2)
    
      // USER CODE END
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the ASC0 Baudrate Generator:
      ///  -----------------------------------------------------------------------
      ///  - fractional divider as prescaler for baud rate timer is used
    
      ASC0_FDV       =  0x00AD;      // load ASC0 fractional divider register
    
      ///  - required baud rate = 38,400 kbaud
      ///  - real baud rate     = 38,397 kbaud
      ///  - deviation          = -0,009 %
    
      ASC0_BG        =  0x000A;      // load ASC0 baud rate time reload register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the ASC0 Operation Mode:
      ///  -----------------------------------------------------------------------
      ///  - 8-bit data asychronous operation with one stop bit
      ///  - receiver is enabled
      ///  - fractional divider is enabled
    
      ASC0_CON       =  0x0811;      // load ASC0 control register
    
      ///  -----------------------------------------------------------------------
      ///  FIFO Configuration:
      ///  -----------------------------------------------------------------------
      ///  - receive FIFO is disabled
      ///  - transmit FIFO is disabled
    
      ASC0_RXFCON    =  0x0102;      // load ASC0 receive FIFO control register
      ASC0_TXFCON    =  0x0102;      // load ASC0 transmit FIFO control register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ASC0 Port Pins:
      ///  -----------------------------------------------------------------------
      ///  - P3.10 is used for ASC Transmit Data Output (TxDA0)
      ///  - P3.11 is used for ASC0 Receive data Input (RxDA0)
    
      ALTSEL0P3     |=  0x0400;      // select alternate output function
      P3   = (P3   & ~(uword)0x0400) | 0x0400;    //set data register
      DP3  = (DP3  & ~(uword)0x0400) | 0x0400;    //set direction register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ASC0 Interrupts:
      ///  -----------------------------------------------------------------------
    
      // USER CODE BEGIN (ASC0_Function,3)
    	ASC0_TIC_IR=1;							// Start KEIL printf()
      // USER CODE END
    
      ASC0_CON      |=  0x8000;      // enable baud rate generator
    
    
    } //  End of function ASC0_vInit
    

    Stefan

Children