This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

configuring UART of c5515

first of all i want some sample codes to work with c5515 of all pheripherals dont show me the way to chip support libarary i can learn nothing from them

here my question is my problem to do basic uart communication using 100Mhz-clk,9600 baud,1start,1stop,noparity ,8data in non fifo mode

here is my code:

uart.c

----------------------------------

/*
* uart_fun.c
*
* Created on: Mar 28, 2013
* Author: shyam
*/
#include<uart_fun.h>
#include<stdio.h>
void uart_init(void);
/*
* involves intialisation of uart setting pll to 100Mhz and selection of 9600 baud
*/
char uart_read(void);
/*
* invloves reading a character through uart and return to called function
*/
void uart_write(char);
/*
* involves writing a character through uart
*/
void uart_wstring(char*);
/*
* involves writing a string through uart possibly adress of string is sent
*/
void uart_init(void)
{
int i;
//setting PLL to 100Mhz
// bypass PLL
CONFIG_MSW = 0x0;
PLL_CNTL2 = 0x8000;
PLL_CNTL4 = 0x0000;
PLL_CNTL3 = 0x0806;
PLL_CNTL1 = 0x8BE8; //PG1.4: 0x82FA;
////// ( (PLL_CNTL3 & 0x0008) == 0);
for(i = 0 ; i < 5000; i++);
// Switch to PLL clk
CONFIG_MSW = 0x1;
//Pin multiplexing by EBSR
EBSR|=0x1a3f;
//Enable uart clock in pcgcr1
PCGCR1&=(~(1<<2));
//Putting UART Tx and Rx Reset through PWREMU_MGMT
PWREMU_MGMT=0X7FFF;
//selecting baud by writing app divisor in DLL DLH
//9600 Baud at 100Mhz clock value to be loaded is 28B
DLL|=0X008b;
DLH|=0X0002;
//choosing FIFO or non-FIFO mode
FCR=0X0000;//non fifo
//Configure LCR for start,stop,non parity,8 data bits
LCR=0X0003;
//ENABLE INTERRUPTS
IER=0X0002;
//DONE
printf("UART Initialization Done");
}
char uart_read(void)
{
char byte_read=0;
while(!(1&LSR));//WAIT FOR DATA TO BE READY

return(byte_read=RBR);

}
void uart_write(char byte2write)
{
while(!(1&(LSR>>5)));//wait until buffer is empty
THR=byte2write;

}

----------------------------------------------------------------------

main.c

------------------------------------------------------------------------------

void main(void)
{
uart_init();
while(1)
{
uart_write(uart_read());
}
}

----------------------------------------------------------------------------

problem:

not able to do possible UART communication,i am able to read from uart but not able to write back,thus i am not able to see the echo of characters on serial terminal

confusions:

i am aware of 8051 in which transmission interrupt specifies completion of transmission later we clear it ,in above case how can i do it in c5515 processor

and during Rx ,Rx interrrupt flag is set and further we clear and take data in buffer ,how can that could be done in c5515 processor 

so for these confusions i have been asking some sample codes from TI,this is a serious problem ,your CSL dont say a learner whats happening with processor just writing a function call cant solve the quench of a beginner try to identify this need of begineers and do the need

thank you 

  • ok problem is with

                "uart_write(uart_read());"

    mean while i have taken a temp variable like this

                  temp=uart_read();

                  uart_write(temp);

    This solved the problem

  • Have tried the UART for higher baud rate, I have tried the same code but  above 9600 baud rate it is not working properly?

  • Did you try using the latest CSL examples on UART ?

    Suggest you to use the latest CSL UART example code. The current example code is with Baud rate 2400, you may need to  modify the code to work with 9600 baud rate  or any other Baud rates.

    Regards

     Vasanth

     

  • Here i have attached the UART.C file and UART.H which has got all routines you requrired for operating c55x device up 460800 baud 

    enjoy !

    0042.UART.c
    #include "Uart.h"
    #include "Data_type.h"
    #include "Common.h"
    #include "stdlib.h"
    
    
    //#define BAUDRATE	57600
    //#define BAUDRATE	115200
    void UART_tx_short(short txb)
    { // Transmit txb on UART
    UART_THR = txb ;
    }
    void UART_SelectBaud(int l_baudrate)
    {
    	Uint16 test;
    	unsigned long baudratedivider;
    	baudratedivider = 0;
    	
    	switch (l_baudrate) 
    	{
    		case 0x0: //12Mhz - 57600
    			baudratedivider = (unsigned long)(12000000) / (unsigned long)57600 ;
    			test = (Uint16)baudratedivider / (Uint16)16;
    			UART_DLL = test & 0x00FF;
    			test = test >> 8 ;
    			UART_DLH = test & 0x00FF;
    			break;
    		case 0x1:	//100Mhz - 115200
    			//Use 100Mhz as clock
    			
    			switch (0)
    			{
    				case 0x1:
    					baudratedivider = (unsigned long)(100000000) / (unsigned long)57600;
    					test = (Uint16)baudratedivider / (Uint16)16 ;
    					UART_DLL = test & 0x00FF;
    					test = test >> 8 ;
    					UART_DLH = test & 0x00FF;
    					break;
    				case 0x0:
    					baudratedivider = (unsigned long)(100000000) / (unsigned long)115200 ;
    					test = (Uint16)baudratedivider / (Uint16)16 ;
    					UART_DLL = test & 0x00FF;
    					test = test >> 8 ;
    					UART_DLH = test & 0x00FF;
    					break;
    			}
    			break;
    	}
    }
    
    /* ------------------------------------------------------------------------ *
     *                                                                          *
     *  _UART_init( )                                                            *
     *                                                                          *
     *      Enable and initalize the UART module                                 *
     * ------------------------------------------------------------------------ */
    int UART_init(int clkfeq)
    {
    	
    
    			//Place the UART transmitter and receiver in reset by setting UTRST and URRST to 0 in the UART power(PWREMU_MGMT).
    			UART_PWREMU_MGMT = 0 ;
    			UART_LCR=0x03;
    			UART_FCR=0;
    			//select baud rate
    			UART_SelectBaud(clkfeq);
    			//UART_LCR= UART_LCR | 0x03
    			UART_MCR=0;
    			//	UART_PWREMU_MGMT = 0x6003 ;
    			UART_PWREMU_MGMT = 0x7fff ;	
    			//enable Uart interrupt flag pending
    			UART_IER = 0x0020 ;
    			//	g_UART_TRANSMIT_FLAG = 0 ;
    			INITIALIZATION_STATUS = UART_STATUS ;
    
    	return(0);
    	
    }
    #if(0)
    int UART_init(int clkfeq)
    {
    	
    	#if(IsBootLoaderRun == 0x1)
    	
    	#elif(IsBootLoaderRun == 0x0)
    
    	volatile int bclkval;
    	//Place the UART transmitter and receiver in reset by setting UTRST and URRST to 0 in the UART power(PWREMU_MGMT).
    	UART_PWREMU_MGMT = 0 ;
    
    	UART_LCR=0x03;
    	UART_FCR=0;
    	//select baud rate
    	bclkval = 0;
    /*						if(clkfeq == 0)
    						{
    							bclkval = 13;
    							UART_DLL = bclkval & 0x00FF;
    							bclkval = bclkval >> 8 ;
    							UART_DLH = bclkval & 0x00FF;
    						}
    						else if(clkfeq == 1)
    						{
    							bclkval = 54;
    							UART_DLL = bclkval & 0x00FF;
    							bclkval = bclkval >> 8 ;
    							UART_DLH = bclkval & 0x00FF;
    						}*/	
    	UART_SelectBaud(clkfeq);
    	//UART_LCR= UART_LCR | 0x03
    	UART_MCR=0;
    //	UART_PWREMU_MGMT = 0x6003 ;
    	UART_PWREMU_MGMT = 0x7fff ;	
    	//enable Uart interrupt flag pending
    	UART_IER = 0x0020 ;
    //	g_UART_TRANSMIT_FLAG = 0 ;
    
    	INITIALIZATION_STATUS = UART_STATUS ;
    
    	
    	#endif
    	
    	
    	return(0);
    }
    #endif
    
    /*
    void UART_SelectBaud(void)
    {
    	Uint16 test;
    	unsigned long baudratedivider;
    	Uint16 BAUDRATE ;
    
    	baudratedivider = 0;
    
    	if(OperatingSystem_Clock == 0) //12Mhz
    	{
    		BAUDRATE = (Uint16)57600 ;	
    		//use 12 Mhz as Clock
    			baudratedivider = (unsigned long)(12000000) / (unsigned long)BAUDRATE ;
    			test = (Uint16)baudratedivider / (Uint16)16;
    			UART_DLL = test & 0x00FF;
    			test = test >> 8 ;
    			UART_DLH = test & 0x00FF;
    	}
    	else if(OperatingSystem_Clock == 1) //100Mhz
    	{
    		BAUDRATE = (Uint16)115200 ;
    		//Use 100Mhz as clock
    		baudratedivider = (unsigned long)(100000000) / (unsigned long)BAUDRATE ;
    		test = (Uint16)baudratedivider / (Uint16)16 ;
    		UART_DLL = test & 0x00FF;
    		test = test >> 8 ;
    		UART_DLH = test & 0x00FF;
    
    	}
    }
    */
    #if(0)
    void UART_SelectBaud(void)
    {
    	if(USE_2400_BAUDRATE)
    	{
    	}
    	else if(USE_4800_BAUDRATE)
    	{
    	}
    	else if(USE_9600_BAUDRATE)
    	{
    		// baud rate 	9600
    		UART_DLL = 0x008B ; // baud rate 9600 and clk=100 Mhz >- 100M/(9600*16)
    		UART_DLH=0x0002 ;
    	}
    	else if(USE_19200_BAUDRATE)
    	{
    	}
    	else if(USE_38400_BAUDRATE)
    	{
    		//baud rate 38400
    		UART_DLL = 0x00A2 ; // baud rate 38400 and clk=100 Mhz >- 100M/(38400*16)
    		UART_DLH=0x0000 ;
    	}
    	else if(USE_56000_BAUDRATE)
    	{
    		//baud rate 56000
    	//	UART_DLL = 0x0070 ; // baud rate 56000 and clk=100 Mhz >- 100M/(56000*16)
    		UART_DLH=0x0000 ;
    	}
    	else if(USE_115200_BAUDRATE)
    	{
    		//baud rate 115200
    		UART_DLL = 0x0036 ; // baud rate 115200 and clk=100 Mhz >- 100M/(115200*16)
    		UART_DLH=0x0000 ;
    	}
    	else if(USE_128000_BAUDRATE)
    	{
    		//baud rate 128000
    		UART_DLL = 0x0031 ; // baud rate 128000 and clk=100 Mhz >- 100M/(128000*16)
    		UART_DLH=0x0000 ;
    	}
    
    	
    }
    #endif
    /***************************************************
     * UART Read Write
     * ****************************************************/
    /* old
    short UART_Read(void)
     {
     	UART_LCR = 0x03;
     	while(UART_LSR | 0x1);
     	return UART_RBR; 
     }
    */
     unsigned char UART_Read(void)
     {
     return(UART_RBR) ;
     }
    
     
     void UART_Write_5_3_Compressed(short ldata)
     {
     	char PCM_send[2];
     	
     	PCM_send[0]= (char)ldata;  //msb
     	PCM_send[1]= (char)(ldata >> 8) ;
     	
     	while(!(UART_LSR & 0x20));
    		UART_THR= PCM_send[1];
    	while(!(UART_LSR & 0x20));
    	 	UART_THR= PCM_send[0];
     		
    }
    
    
    
    void UART_Write_6_3_Compressed(short ldata)
    {
     	char PCM_send[2];
     	
     	PCM_send[0]= (char)ldata;  //msb
     	PCM_send[1]= (char)(ldata >> 8) ;
     	
     	 
     	while(!(UART_LSR & 0x20));
     		UART_THR= PCM_send[0];
     	while(!(UART_LSR & 0x20));
     		UART_THR= PCM_send[1];
     	
    }
    
    
    
    void UPrintf(char * lprintfDatam)
    {
    	char *sptr;
    	
    	sptr = lprintfDatam ;
    	while(*sptr) 
    	{
    		while(!(UART_LSR & 0x20));
    		UART_THR= *sptr++;
    	}
    }
    
    void UART_Write(short ldata)
    {
     	char PCM_send[2];
     	
     	PCM_send[0]= (char)ldata;  //lsb
     	PCM_send[1]= (char)(ldata >> 8) ; //msb
      	 
     	while(!(UART_LSR & 0x20));
     		UART_THR= PCM_send[1]; //send Msb first first
     	while(!(UART_LSR & 0x20));
     		UART_THR= PCM_send[0];
     	
    }
    
    void Printc(unsigned char ldata)
    {
     	while(!(UART_LSR & 0x20));
     		UART_THR= ldata; //send Msb first first
    
    }
    
    unsigned char UART_tx_free(void)
    { // Return 0 if UART_tx Busy, else 1
    return(UART_LSR & UART_TEMT) ;
    }
    void UART_tx_byte(unsigned char txb)
    { // Transmit txb on UART
    UART_THR = txb ;
    }
    unsigned char UART_rx_full(void)
    { // Return 1 if data byte received on UART
    return(UART_LSR & UART_RX_RDY) ;
    }
    
    
    
    
    void prints(unsigned char *prstr_ptr)
    {
    while(*prstr_ptr)
    	{
    	if(UART_tx_free())
    		{
    		UART_tx_byte(*prstr_ptr++) ;
    		}
    	}	
    }
    
    
    void print_hex_byte(unsigned int pr_data)
    {
    char prstr[3] ;
    unsigned char hex_tbl[] = {"0123456789ABCDEF"} ;
    
    prstr[0] = hex_tbl[((pr_data / 16))& 0x0f] ;
    prstr[1] = hex_tbl[(pr_data % 16)& 0x0f] ;
    prstr[2] = 0 ;//eos
    prints((unsigned char*)&prstr[0]) ;
    }
    void print_hex_int(unsigned int data)
    {
    char hex[5];
    unsigned char hex_tbl[] = {"0123456789ABCDEF"} ;
    hex[4]	=	0;//eos
    hex[3]	=	hex_tbl[(data)%16];
    data	=	data/16;
    hex[2]	=	hex_tbl[(data)%16];
    data	=	data/16;
    hex[1]	=	hex_tbl[(data)%16];
    data	=	data/16;
    hex[0]	=	hex_tbl[(data)%16];
    prints((unsigned char*)hex);
    }
    void print_int(unsigned int adc_data)
    {
    char prstr[8] ;
    
    ltoa((long int)adc_data , &prstr[0]);
    
    /*
    unsigned char hex_tbl[] = {"0123456789ABCDEF"} ;
    
    
    prstr[0] = hex_tbl[(adc_data / 1000) & 0x0f] ;
    prstr[1] = hex_tbl[((adc_data / 100) % 10)& 0x0f] ;
    prstr[2] = hex_tbl[((adc_data / 10) % 10)& 0x0f] ;
    prstr[3] = hex_tbl[(adc_data % 10)& 0x0f] ;
    prstr[4] = 0 ;
    
    
    */
    
    prints((Uint8 *)&prstr[0]) ;
    }
    
    interrupt void UART_Isr(void)
    {
    
    //	IFR0 = IFR0 & 0x0040; 
    //	g_UART_TRANSMIT_FLAG = 1;
    	
    }
    
    
    

    8524.Uart.h

  • Hi

    Did you solove the problem?

    I am learning ezdsp 5515 stick recently. I didn't find any library about UART either. Can you tell me where can I get the lib and the sample code?

    BTW , are the files you attached appropriate for common use of UART  in 5515?

    Thanks!

    Regards,

    Chunhai