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

  • 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

  • Hello Stefan,

    thanks for your fast reply. The flag is set during the initalization and before using printf the first time.

    Do you know anything else what could cause such a behaviour?

    Btw I am using a phyCORE XC161 and the example hello.h86 works.

    Sebastian

  • My mistakes at beginning were
    ( I had only a Infineonboard)
    - forget to enable ASC in general (SYSCON3)
    - set wrong clock values
    - forget enable the receiver

    Can we check your code?

    Stefan

  • This is my code:

    	ASC0_BG 	= 0x4; 					//BG fĂĽr 57600 kbit/s
    
    	ASC0_FDV	= 0x76;					//Fractional Divider fĂĽr 57600 kbit/s
    
    	ASC0_CON 	= 0x0811;				//8 bit daten async., 1 Stopbit, Receiver an
    
    	ALTSEL0P3 	&= 0xF7FF;				//Alternative Funktion Port 3.10 und 3.11 an
    
    	P3 			|= 0x0400;				//P3.10 auf High, P3.11 auf Low
    	DP3 		|= 0x0400;				//P3.10 als Output P3.11 als Input
    
    	ASC0_TIC	= 0x0080;				//Tx G-Lv 01, I-Lv 0101, Tx_IE = 1
    
    	ASC0_RXFCON	= 0x0102;
    
    	ASC0_TXFCON = 0x0102;
    
    	ASC0_RIC 	= 0x0000;				//Rx G-Lv 01, I-Lv 1001, Rx_IE = 1
    
    	ASC0_TIC_IR = 1;
    
    	ASC1_CON_R	= 1;					//Baudratengenerator an
    

    i got the values for the BG and fractional divider from the manual of the XC161. In Syscon3 the ASC0 is activated.

  • I forgot to mention that i used also used DAvE for creating the initilization code. The values in the comments for the interrupt settings of ASC0 Rx and Tx are from an older version.

    Sebastian

  • Is it right that you set ASC1_CON instead of ASC0_CON ?
    Otherwise the code looks good.
    Did you check boardsettings?

    Stefan

  • Oops. This is supposed to be ASC0...
    I changed it but it still does not work.
    The Boardsettings should be alright according to the manual of PHYTEC. There is only one problem i just came across. When i am trying to use the PLL-Config for the CPU-clock in DAvE it is shown as to high to use but the interrupt is still working.
    I will have a closer look at that issue and the boardsettings.

    Sebastian

  • Ok - please keep me informed.
    If I can provided with my PLL settings, let me know.

    Stefan

  • I checked and corrected the PLL-settings but it is still not running.
    There still might be some problem with the SYSCON SFRs. I don't know where else the problem might be.
    Could you please post a working configuration of your SYSCON registers?

    Sebastian

  • SYSCON1 = 0x0000
    SYSCON3 = 0x80C0

    PLLCON = 7844

    Stefan

  • Thanks for your help,
    unfortunately it is still not working.
    I don't have any idea what could be another possible error source.

    Sebastian

  • Maybe the rs232 driver is defctive ?

    Stefan

  • i don't think so because when i use the hello.h86 file from phytec the rs232 interface works. hello can be seen in hyper terminal.

    Sebastian

  • please send me your source to
    stefan_fricke@rutronik.com
    I will check with my board here.

    Stefan