Uart Read in adsp21489
Hi
Iam trying to read some data from Uart through Getchar and writing the same data through uart using Putchar .But Getchar is not reading the properly.Can i know what is the problem in the code.I attached the code below Please let me know what is the problem and correct me what i did mistake.
Fullscreen
u.txt
Download
unsigned char *value;
void Init_UART(void)
{
volatile int temp;
int picr2 = 0x0;
/* maps the UART0 receive interrupt to P14 using the programmable interrupt controller */
picr2 = *pPICR2; /* get PICR2 */
picr2 &= (~(0x1f<<10)); /* clear P14 bits */
picr2 |= (0x13<<10); /* set UART0RX */
(*pPICR2) = picr2; /* put it back */
sysreg_bit_set(sysreg_IMASK, P14I ); /* unmask UART RX interrupt */
/* (*pUART0IER) = UARTRBFIE;*/ /* enable UART RX interrupt */
SRU2(UART0_TX_O,DPI_PB09_I); /* UART TX signal is connected to DPI pin 9 */
SRU2(HIGH,DPI_PBEN09_I);
SRU2(DPI_PB10_O,UART0_RX_I); /* connect the pin buffer output signal to the UART0 RX */
SRU2(LOW,DPI_PB10_I);
SRU2(LOW,DPI_PBEN10_I); /* disable DPI pin10 as input */
(*pUART0LCR) = UARTDLAB; /* enables access to divisor register to set baud rate */
#ifdef __ADSP21469__
(*pUART0DLL) = 0xdc;
(*pUART0DLH) = 0x2; /* 0x2dc = 732 for divisor value gives a baud rate of 19200 at 450 Mhz core clock */
#elif (__ADSP21479__)
(*pUART0DLL) = 0xb0;
(*pUART0DLH) = 0x1; /* 0x1B0 = 432 for divisor value gives a baud rate of 19200 at 266 Mhz core clock */
#elif (__ADSP21489__)
(*pUART0DLL) = 0x8b;
(*pUART0DLH) = 0x2; /* 0x28b = 651 for divisor value gives a baud rate of 19200 at 400 Mhz core clock */
#endif
(*pUART0LCR) = (UARTWLS8 | UARTPEN | UARTSTB); /* 8 bit word, odd parity, 2 stop bits */
(*pUART0RXCTL) = UARTEN; /* enable UART0 RX */
(*pUART0TXCTL) = UARTEN; /* enable UART0 TX */
}
/*******************************************************************
* Function: PutChar
* Description: Writes a character to the UART.
*******************************************************************/
int PutChar(const char cVal)
{
int nStatus = 0;
unsigned int count = 0;
do
{
if( (*pUART0LSR & UARTTHRE) )
{
*pUART0THR = cVal;
nStatus = 1;
break;
}
count++;
} while( count < 0x100000 );
return nStatus;
}
/*******************************************************************
* Function: GetChar
* Description: Reads a character from the UART.
*******************************************************************/
int GetChar(char *const cVal)
{
int nStatus = 0;
unsigned int count = 0x0;
do{
if( UARTDR == (*pUART0LSR & UARTDR))
{
*cVal = (char)*pUART0RBR;
nStatus = 1;
break;
}
count++;
}while( count < 0x100000 );
return nStatus;
}
void main(void)
{
adi_initComponents();
Init_UART();
while(1)
{
// Test_UART();
GetChar(&value);
PutChar(value);
}
}
Hi Mounika,
Please find the attached UART loopback example for ADSP-21479. This can be directly run on the ADSP-21479 EZ-Kit. Please use this code as a reference and modify as per your requirement. You can understand the working of the code from the comments embedded within.
Regards,
Jithul
UART_DMA.zip
Please log in to reply.