реклама на сайте
подробности

 
 
> SK-MLPC2368, работа с UART1 одновременно с UART0
Fellrond
сообщение Feb 8 2011, 15:05
Сообщение #1





Группа: Новичок
Сообщений: 4
Регистрация: 26-11-10
Пользователь №: 61 197



Доброго времени суток,

Есть проект по реализации Ethernet-RS232 моста на основе платы SK-MLPC2368 (чип, соответственно LPC2368). На плате разведен DP9-разъем для UART0. Для вывода отладочной информации понадобилось вывести так же UART1. В итоге, при передаче в UART1 байты неистово бьются, вернее, даже не бьются - приходит полная ахинея. С UART0 с той же инициализацией (за исключением прерываний) - работает нормально.

Помимо этого проект включает в себя FreeRTOS и uIP. В FreeRTOS запущен только один процесс - uIP.

Гуру, помогите разобраться заблудшему. За 3 дня копания доков уже запутался окончательно. Помогите пожалуйста поднять UART1.

Код инициализации и работы с UART прилагается. RXD1 и TXD1 выведены на 62 и 63 ноги процессора (выводы платы - MK_P62 и MK_P63).

Инициализация:
Код
    /*
     *     Following settings configures UART0 to 8bit, 1 stop bit
     */
void setupUART0(uchar DLL)
{                            //                                ( 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 )
    PINSEL0 &= 0xFFFFFF0F;     // clear UART0 (P0.xx) PINSEL0    ( xx xx xx xx xx xx xx xx xx xx xx xx 00 00 xx xx )
    PINSEL0 |= 0x00000050;     // set     UART0 (P0.xx) PINSEL0    ( xx xx xx xx xx xx xx xx xx xx xx xx 01 01 xx xx )
    PCONP |= (1 << 3);        // power-up UART0
    U0LCR = 0x83;             // DLAB = 1 to set baud rate by DLL
    U0DLL = DLL;             // set a UART prescaler
    U0FDR = 0x10;            // set a UART divisor
    U0DLM = 0;                // set a UART multiplier
    U0LCR = 0x03;             // DLAB = 0 to protect current DLL settings
    U0FCR = 0x07;            // enable UART FIFOs and clear them
    VICIntEnable |= (1 << 6);    // set interrupt control for UART
    VICVectCntl6 = 1;            // set interrupt priority for UART (vector 6)
    VICVectAddr6 = ( portLONG ) U0IRQ; // set interrupt function
    U0IER = 0x00000001;        // enable UART0 receiver interrupt
}

void setupUART1(uchar DLL)
{                            // "xx" is not important        ( 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 )
    PINSEL0 &= 0x3FFFFFFF;    // clear UART1 (P0.15) PINSEL0    ( 00 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx )
    PINSEL0 |= 0x40000000;    // set      UART1 (P0.15) PINSEL0    ( 01 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx )
    PINSEL1 &= 0xFFFFC000;    // clear UART1 (P1.xx) PINSEL1    ( xx xx xx xx xx xx xx xx xx 00 00 00 00 00 00 00 )
    PINSEL1 |= 0x00001555;    // set      UART1 (P1.xx) PINSEL1    ( xx xx xx xx xx xx xx xx xx 01 01 01 01 01 01 01 )
//    PINSEL4 &= 0xFFFFFFF0;    // clear UART1 (P2.xx) PINSEL4    ( xx xx xx xx xx xx xx xx xx xx xx xx xx xx 00 00 )
//    PINSEL4 |= 0x0000000A;    // set      UART1 (P2.xx) PINSEL4    ( xx xx xx xx xx xx xx xx xx xx xx xx xx xx 10 10 )
    PCONP |= (1 << 4);        // power-up UART1
    U1LCR = 0x83;             // DLAB = 1 to set baud rate by DLL
    U1DLL = DLL;             // set a UART prescaler
    U1FDR = 0x10;            // set a UART divisor
    U1DLM = 0;                // set a UART multiplier
    U1LCR = 0x03;             // DLAB = 0 to protect current DLL settings
    U1FCR = 0x07;            // enable UART FIFOs and clear them
}


Прерывание UART0:
Код
extern uchar UARTbuf[UIP_CONF_BUFFER_SIZE];
extern int UARTcount;
volatile uchar IIRValue, LSRValue, UART0Status;
volatile uchar Dummy;

void __attribute__ ((naked)) U0IRQ(void)
{
    portSAVE_CONTEXT();

    IIRValue = U0IIR;

    IIRValue >>= 1;            /* skip pending bit in IIR */
    IIRValue &= 0x07;            /* check bit 1~3, interrupt identification */
    if ( IIRValue == IIR_RLS )        /* Receive Line Status */
    {
        LSRValue = U0LSR;
        /* Receive Line Status */
        if ( LSRValue & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI) )
        {
            /* There are errors or break interrupt */
            /* Read LSR will clear the interrupt */
            UART0Status = LSRValue;
            Dummy = U0RBR;        /* Dummy read on RX to clear
                                interrupt, then bail out */
        }
        else if ( LSRValue & LSR_RDR )    /* Receive Data Ready */
        {
            /* If no error on RLS, normal ready, save into the data buffer. */
            /* Note: read RBR will clear the interrupt */
            UARTbuf[UARTcount] = U0RBR;
            UARTcount++;
            if ( UARTcount == UIP_CONF_BUFFER_SIZE )
            {
                UARTcount = 0;        /* buffer overflow */
            }
        }
    }
    else if ( IIRValue == IIR_RDA )    /* Receive Data Available */
    {
        /* Receive Data Available */
        UARTbuf[UARTcount] = U0RBR;
        UARTcount++;
        if ( UARTcount == UIP_CONF_BUFFER_SIZE )
        {
            UARTcount = 0;        /* buffer overflow */
        }
    }
    else if ( IIRValue == IIR_CTI )
    {
        if ( U0LSR & 1 )
        {
            UARTbuf[UARTcount] = U0RBR;
            UARTcount++;
            if ( UARTcount == UIP_CONF_BUFFER_SIZE )
            {
                UARTcount = 0;        /* buffer overflow */
            }
        }
    }

    VICVectAddr = 0;        /* Acknowledge Interrupt */

    portRESTORE_CONTEXT();
}


Запись в UART:
Код
void writeByteUART0(uchar byte)
{
    while (!(U0LSR & (1 << 5)));
    U0THR = byte;
}

void writeArrayUART0(uchar *arr, int len)
{
    for (int i = 0; i < len; i++)
    {
        writeByteUART0(arr[i]);
    }
}

void writeMessageUART0(const char *msg)
{
    int len = strlen(msg);
    writeArrayUART0((uchar *) msg, len);
}

void writeDebugMessageUART0(const char *msg)
{
#ifdef DEBUG_MESSAGES
    int len = strlen(msg);
    writeArrayUART0((uchar *) msg, len);
#endif
}

void writeByteUART1(uchar byte)
{
    while (!(U1LSR & (1 << 5)));
    U1THR = byte;
}

void writeArrayUART1(uchar *arr, int len)
{
    for (int i = 0; i < len; i++)
    {
        writeByteUART1(arr[i]);
    }
}

void writeMessageUART1(const char *msg)
{
    int len = strlen(msg);
    writeArrayUART1((uchar *) msg, len);
}

void writeDebugMessageUART1(const char *msg)
{
#ifdef DEBUG_MESSAGES
    int len = strlen(msg);
    writeArrayUART1((uchar *) msg, len);
#endif
}


Сообщение отредактировал Fellrond - Feb 8 2011, 15:06
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов (1 - 2)
Fellrond
сообщение Feb 9 2011, 10:05
Сообщение #2





Группа: Новичок
Сообщений: 4
Регистрация: 26-11-10
Пользователь №: 61 197



Попытался завести аналогично UART2.

Код
void setupUART2(uchar DLL)
{                            // "xx" is not important        ( 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 )
    PINSEL0 &= 0xFF0FFFFF;    // clear UART2 (P0.xx) PINSEL0    ( xx xx xx xx 00 00 xx xx xx xx xx xx xx xx xx xx )
    PINSEL0 |= 0x00500000;    // set      UART2 (P0.xx) PINSEL0    ( xx xx xx xx 01 01 xx xx xx xx xx xx xx xx xx xx )
    PCONP |= (1 << 24);        // power-up UART2
    U2LCR = 0x83;             // DLAB = 1 to set baud rate by DLL
    U2DLL = DLL;             // set a UART prescaler
    U2FDR = 0x10;            // set a UART divisor
    U2DLM = 0;                // set a UART multiplier
    U2LCR = 0x03;             // DLAB = 0 to protect current DLL settings
    U2FCR = 0x07;            // enable UART FIFOs and clear them
}


Симптомы аналогичны UART1 - приходит ахинея, хотя и совпадает по количеству байт. TXD и RXD подключены к 48-49 ногам процессора.
Go to the top of the page
 
+Quote Post
Fellrond
сообщение Feb 10 2011, 13:42
Сообщение #3





Группа: Новичок
Сообщений: 4
Регистрация: 26-11-10
Пользователь №: 61 197



Идиотская проблема разрешилась по-идиотски: я не знал о необходимости установки драйвера COM-порта для работы с RS232 компьютера. Припаял к проводу max232 - все завелось.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 22nd July 2025 - 01:32
Рейтинг@Mail.ru


Страница сгенерированна за 0.01382 секунд с 7
ELECTRONIX ©2004-2016