MQX 4.1 UART RX problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX 4.1 UART RX problem

Jump to solution
1,088 Views
oscargarciaabad
Contributor III

Hi all,

 

I'm trying to communicate with a WIFI module from Inventek using UART. This module uses AT commands.

 

I configure the UART0 channel in 115200 8 N 1 mode. Then I send to the module the command "AT\r\n". Then I can see in the oscilloscope the answer from the module (this answer is more tha 30 bytes long as I can tell by the time duration of that answer).

 

The problem is I only can read 7 bytes from this response. After thta I try again with the same result (Only read the first seven bytes of the answer).

 

I tried with different UART channels and both interrupt and polling driver with the same result. I tried too with read and fread functions an the result is still the same. (Find attached my user_config.h file).

 

The code I'm using is:

 

#include <mqx.h>

#include <bsp.h>

#include "serial.h"

#include "ioctl.h"

#include "mutex.h"

 

#define WUART_CHANNEL    "ittya:"

#define WUART_BAUDRATE   ( 115200uL )

#define WUART_STOP_BITS  IO_SERIAL_STOP_BITS_1

#define WUART_DATA_BITS  8

#define WUART_PARITY     IO_SERIAL_PARITY_NONE


typedef struct

    MQX_FILE_PTR        ChannelFD;   /* UART Channel FD */

    uint32_t            Baudrate;    /* UART Baudrate */

    uint32_t            Parity;      /* UART Parity */

    uint32_t            StopBits;    /* UART Stop Bits */

    uint32_t            DataBits;    /* UART Data Bits */

    MUTEX_STRUCT        uartMutex;

} WUART_INFO;

 

extern uint32_t WUART_init( WUART_INFO *uartCtx_Ptr)

{

    uint32_t retValue = ENET_OK;

    uint8_t Buffer[64];

    int32_t BytesRead, Index;

   

    /*

    * * * * * * * * * *

    * Init Ctx struct

    * * * * * * * * * *

    */

    uartCtx_Ptr->Baudrate = WUART_BAUDRATE;

    uartCtx_Ptr->Parity = WUART_PARITY;

    uartCtx_Ptr->StopBits = WUART_STOP_BITS;

    uartCtx_Ptr->DataBits = WUART_DATA_BITS;

    /*

    * * * * * * * * * * * *

    * Open the serial port

    * * * * * * * * * * * *

    */

    uartCtx_Ptr->ChannelFD = fopen( WUART_CHANNEL,

                                    (const char *)( IO_SERIAL_RAW_IO |

                                                    IO_SERIAL_NON_BLOCKING) );

    if(uartCtx_Ptr->ChannelFD == NULL )

    {

        retValue = ENETERR_INIT_FAILED;

    }

    else

    {

        /*

        * * * * * * * * * * *

        * Set UART baudrate

        * * * * * * * * * * *

        */

        if( ioctl( uartCtx_Ptr->ChannelFD,

             IO_IOCTL_SERIAL_SET_BAUD,

             &uartCtx_Ptr->Baudrate ) != ( uint32_t ) MQX_OK )

        {

            retValue = ENETERR_INIT_FAILED;

        }

    }

    if( retValue == ENET_OK )

    {

        /*

        * * * * * * * * * *

        * Set UART Parity

        * * * * * * * * * *

        */

        if( ioctl( uartCtx_Ptr->ChannelFD,

             IO_IOCTL_SERIAL_SET_PARITY,

             &uartCtx_Ptr->Parity ) != ( uint32_t ) MQX_OK )

        {

            retValue = ENETERR_INIT_FAILED;

        }

    }

    if( retValue == ENET_OK )

    {

        /*

        * * * * * * * * * * *

        * Set UART Stop Bits

        * * * * * * * * * * *

        */

        if( ioctl( uartCtx_Ptr->ChannelFD,

             IO_IOCTL_SERIAL_SET_STOP_BITS,

             &uartCtx_Ptr->StopBits ) != ( uint32_t ) MQX_OK )

        {

            retValue = ENETERR_INIT_FAILED;

        }

    }

    if( retValue == ENET_OK )

    {

        /*

        * * * * * * * * * * *

        * Set Data Bits

        * * * * * * * * * * *

        */

        if( ioctl( uartCtx_Ptr->ChannelFD,

             IO_IOCTL_SERIAL_SET_DATA_BITS,

             &uartCtx_Ptr->DataBits ) != ( uint32_t ) MQX_OK )

        {

            retValue = ENETERR_INIT_FAILED;

        }

    }

    memset(Buffer, 0, 20);

    write(uartCtx_Ptr->ChannelFD, "AT\r\n", 4);

    while(1)

    {

        BytesRead = fread(Buffer, 1, 1, uartCtx_Ptr->ChannelFD);

        if(BytesRead > 0 )

        {

                printf("%c", Buffer[0]);

                fflush( stdout );

        }

    }

    return( retValue );

}

Original Attachment has been moved to: user_config.h.zip

0 Kudos
Reply
1 Solution
739 Views
oscargarciaabad
Contributor III

Hi David,

First of all thank you for your help. I Changed BSP_DEFAULT_IO_CHANNEL to "ittyf:" and used TWR-SER for the console output. The result is still the same. I took a look at the TWR-K60F120M schematics and I noticed that PTA1 and PTA2 are connected to the JTAG header. I'm debugging using JTAG... the problem disappear when I'm not debugging the system!

I'm going to try to debug using Open-SDA.

Thanks a lot,

Oscar.

View solution in original post

0 Kudos
Reply
4 Replies
739 Views
DavidS
NXP Employee
NXP Employee

Hi Oscar,

Your user_config.h has following:

#define BSP_DEFAULT_IO_CHANNEL "iodebug:"

This implies to me that you are using the debugger interface for your STDIO (printf)....correct?

I can imagine this is a very slow interface and might not be able to keep up with the ittya interface.

Could you try to store the ittya data to a buffer rather than using the printf to see if system works?

Regards,

David

740 Views
oscargarciaabad
Contributor III

Hi David,

First of all thank you for your help. I Changed BSP_DEFAULT_IO_CHANNEL to "ittyf:" and used TWR-SER for the console output. The result is still the same. I took a look at the TWR-K60F120M schematics and I noticed that PTA1 and PTA2 are connected to the JTAG header. I'm debugging using JTAG... the problem disappear when I'm not debugging the system!

I'm going to try to debug using Open-SDA.

Thanks a lot,

Oscar.

0 Kudos
Reply
739 Views
RadekS
NXP Employee
NXP Employee

Hi Oscar,

Thank you for your info about root cause.

Have a great day,
RadekS

0 Kudos
Reply
739 Views
oscargarciaabad
Contributor III

Hi RadekS,

You are welcome!

Regards,

Oscar.

0 Kudos
Reply