AnsweredAssumed Answered

MQX 4.1 UART RX problem

Question asked by Oscar Garcia Abad on Apr 21, 2015
Latest reply on Apr 22, 2015 by Oscar Garcia Abad

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

Outcomes