K60 UART Problems

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

K60 UART Problems

跳至解决方案
3,061 次查看
davidtietz
Contributor III

I am having problems initializing the UARTs on the K60 using MQX 3.8 and CW 10.3.

I had a “daughter board” made to plug into the tower system that gives us access to the UARTs I am trying to use. For this project I am using UART1, UART3, UART4, and UART5. All the UARTs seem to work fine on the transmit side.

I modified the twrk60n512.h file and the user_config.h file to enable the interrupt version of ttyb, ttyc, etc. in the MQX files. I then recompiled all projects.

Below is a snippet of my code to help explain what I am doing.

    uart_ptr1 = fopen("ittyb:", BSP_DEFAULT_IO_OPEN_MODE);

    uart_ptr3 = fopen("ittyd:", BSP_DEFAULT_IO_OPEN_MODE);

    uart_ptr4 = fopen("ittye:", BSP_DEFAULT_IO_OPEN_MODE);

    uart_ptr5 = fopen("ittyf:", BSP_DEFAULT_IO_OPEN_MODE);

   

   

    if(uart_ptr1 == NULL)

    {

        write(uart_ptr3,(pointer)"UART1: failed to open", 20);   

    }

   

    if(uart_ptr3 == NULL)

    {

        write(uart_ptr3,(pointer)"UART3: failed to open", 20);   

    }   

   

    if(uart_ptr4 == NULL)

    {

        write(uart_ptr3,(pointer)"UART4: failed to open", 20);   

    }

   

    if(uart_ptr5 == NULL)

    {

        write(uart_ptr3,(pointer)"UART5: failed to open", 20);    

    }

    write(uart_ptr1,(pointer)"Hello World:UART1\n\r", 17);    // write char to uart1   (works fine)

    write(uart_ptr3,(pointer)"Hello World:UART3\n\r", 17);    // write char to uart3   (works fine)

    write(uart_ptr4,(pointer)"Hello World:UART4\n\r", 17);    // write char to uart4     (works fine)

    write(uart_ptr5,(pointer)"Hello World:UART5\n\r", 17);    // write char to uart5   (works fine)

   

   

    p3_scm_imm();    //Checking to see if there are any new scan or non-scan messages to process

           

    while(1)

    {

        while(fstatus(uart_ptr1))

        {

            ch = fgetc(uart_ptr1);

            write(uart_ptr1,(pointer)ch, 1);   

        }

        while(fstatus(uart_ptr3))

        {

            ch = fgetc(uart_ptr3);

            write(uart_ptr3 ,(pointer)ch, 1);   

        }

        while(fstatus(uart_ptr4))

        {

            ch = fgetc(uart_ptr4);

            write(uart_ptr4,(pointer)ch, 1);   

        }

        while(fstatus(uart_ptr5))

        {

            ch = fgetc(uart_ptr5);

            write(uart_ptr5,(pointer)ch, 1);   

        }

}


In my only task that I call, I send out a “Hello World” from each port. That works okay. The problem lies in the receiving side of things. After initializing the ports, I sit and wait for data to be received. UART3 appears to work fine, but with the exact same code, I cannot seem to get UART1, UART4, or UART5 to work (see above). The code should just echo back out what is received.

Is there something I'm missing in the initialization of the other ports that had already been done to the default port (UART3 – ttyd)?

标记 (3)
0 项奖励
回复
1 解答
1,211 次查看
davidtietz
Contributor III

After beating on this for several days, I finally found the issue. This might be a bug, because I couldn't find this documented. Please correct me if I am wrong.

Even though I was configuring the UART MUX pins correctly, the problem was MQX was initializing other (default) MUX pins to the same UART when I issued the fopen command on the port. In other words, two pins were being allocated to the same UART RX pin. This seemed to be what was causing the problem. I modified my code above to the following.

void init_Com1(void)

{

  

    PORTC_PCR3=PORT_PCR_MUX(0);        //Disable default UART1_TX

    PORTC_PCR4=PORT_PCR_MUX(0);        //Disable default UART1_RX  

  

    PORTE_PCR0=PORT_PCR_MUX(3);        //UART1_TX

    PORTE_PCR1=PORT_PCR_MUX(3);        //UART1_RX

  

}

void init_Com3(void)

{

  

  

    PORTC_PCR16=PORT_PCR_MUX(3);    //UART3_RX  --MQX was defaulting to these pins anyhow.

    PORTC_PCR17=PORT_PCR_MUX(3);    //UART3_TX  

  

}

void init_Com4(void)

{

  

    PORTE_PCR24=PORT_PCR_MUX(0);        //Disable default UART4_TX

    PORTE_PCR25=PORT_PCR_MUX(0);        //Disable default UART4_RX

  

    PORTC_PCR14=PORT_PCR_MUX(3);    //UART4_RX

    PORTC_PCR15=PORT_PCR_MUX(3);    //UART4_TX

  

}

void init_Com5(void)

{

  

    PORTE_PCR8=PORT_PCR_MUX(0);        //Disable default UART5_TX

    PORTE_PCR9=PORT_PCR_MUX(0);        //Disable default UART5_RX

  

    PORTD_PCR8=PORT_PCR_MUX(3);        //UART5_TX

    PORTD_PCR9=PORT_PCR_MUX(3);        //UART5_RX

  

}



Hopefully this solution helps someone out in the future. I couldn't seem to find this problem documented anywhere on the forums either.

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,212 次查看
davidtietz
Contributor III

After beating on this for several days, I finally found the issue. This might be a bug, because I couldn't find this documented. Please correct me if I am wrong.

Even though I was configuring the UART MUX pins correctly, the problem was MQX was initializing other (default) MUX pins to the same UART when I issued the fopen command on the port. In other words, two pins were being allocated to the same UART RX pin. This seemed to be what was causing the problem. I modified my code above to the following.

void init_Com1(void)

{

  

    PORTC_PCR3=PORT_PCR_MUX(0);        //Disable default UART1_TX

    PORTC_PCR4=PORT_PCR_MUX(0);        //Disable default UART1_RX  

  

    PORTE_PCR0=PORT_PCR_MUX(3);        //UART1_TX

    PORTE_PCR1=PORT_PCR_MUX(3);        //UART1_RX

  

}

void init_Com3(void)

{

  

  

    PORTC_PCR16=PORT_PCR_MUX(3);    //UART3_RX  --MQX was defaulting to these pins anyhow.

    PORTC_PCR17=PORT_PCR_MUX(3);    //UART3_TX  

  

}

void init_Com4(void)

{

  

    PORTE_PCR24=PORT_PCR_MUX(0);        //Disable default UART4_TX

    PORTE_PCR25=PORT_PCR_MUX(0);        //Disable default UART4_RX

  

    PORTC_PCR14=PORT_PCR_MUX(3);    //UART4_RX

    PORTC_PCR15=PORT_PCR_MUX(3);    //UART4_TX

  

}

void init_Com5(void)

{

  

    PORTE_PCR8=PORT_PCR_MUX(0);        //Disable default UART5_TX

    PORTE_PCR9=PORT_PCR_MUX(0);        //Disable default UART5_RX

  

    PORTD_PCR8=PORT_PCR_MUX(3);        //UART5_TX

    PORTD_PCR9=PORT_PCR_MUX(3);        //UART5_RX

  

}



Hopefully this solution helps someone out in the future. I couldn't seem to find this problem documented anywhere on the forums either.

0 项奖励
回复
1,211 次查看
JimDon
Senior Contributor III

Is it possible that the TX pins pin mux was set correctly, but not the RX?

Also, are you sure that your board is correctly send the RX data to the proper pins on the MCU?

0 项奖励
回复
1,211 次查看
davidtietz
Contributor III

Hi Jim,

Thanks for the response!

I am fairly certain that the pin muxing have been initialized correctly. I have double checked the schematics for the tower to confirm this. I attached my code below that I am using to initialize these ports.


On Friday, we tried a "bare-metal" project. We used processor expert to configure the ports and run a simple "Hello World" project. All of the ports RX and TX seem to work fine in this simple project. I just can't seem to get them to initialize correctly while using MQX.


Any more help/insight you can provide would be great!



void init_Com3(void)

{

   

   

    PORTC_PCR16=PORT_PCR_MUX(3);        //UART3_RX

    PORTC_PCR17=PORT_PCR_MUX(3);       //UART3_TX

   

   

}

void init_Com1(void)

{

   

   

    PORTE_PCR0=PORT_PCR_MUX(3);        //UART1_TX

    PORTE_PCR1=PORT_PCR_MUX(3);        //UART1_RX

   

   

}

void init_Com4(void)

{

   

   

    PORTC_PCR14=PORT_PCR_MUX(3);        //UART4_RX

    PORTC_PCR15=PORT_PCR_MUX(3);        //UART4_TX

   

   

}

void init_Com5(void)

{

   

    PORTD_PCR8=PORT_PCR_MUX(3);        //UART5_TX

    PORTD_PCR9=PORT_PCR_MUX(3);        //UART5_RX

   

}

0 项奖励
回复