AnsweredAssumed Answered

Problem with UART receive/transmit data

Question asked by BlueIceScream on Mar 27, 2011
Latest reply on Mar 29, 2011 by WassimB

Hello all.

i want do simple data receive and transmit project from UART device.

For this i use uart device driver. i write code but it don't work. I set breakpoint in callback function and send data from PC. My program in debug mode don't stop in breakpoint so it never call my callback function. When i test other application (uart loopback example) all work right.

Please say where i have mistake.

 

 

 

#include <drivers/uart/adi_uart.h>

 

// Buffers count
#define ELEMENT_COUNT               (8) // 8 byte
#define ELEMENT_WIDTH                (1) // 1 byte

 

#define STOP_BITS_COUNT            (1)
#define BAUD_RATE                     (9600)
#define PARITY                         (FALSE)
#define DATA_BITS_COUNT               (8)

 

void UART_Reset();
static void UART_WriteData(unsigned char * data,unsigned char len);
void UARTCallbackFunction(void *ClientHandle, u32 Event, void *pArg);

 

static u8                    UARTInboundData[ELEMENT_COUNT];

static u8                    UARTOutboundData[ELEMENT_COUNT/2];

 

static ADI_DEV_1D_BUFFER     UARTInboundBuffer;

static ADI_DEV_1D_BUFFER     UARTOutboundBuffer;

 

static ADI_DEV_DEVICE_HANDLE UARTHandle;

 

extern void ProcessCommandFromTube();

 

/*********************************************************

/*     Function: Reset UART

/*     Description: reset uart device and config it

/********************************************************/

void UART_Reset()

{

u32                    i;

u32                        Result;

 

ADI_DEV_CMD_VALUE_PAIR UARTConfiguration[] = {

{ ADI_DEV_CMD_SET_DATAFLOW_METHOD,      (void *)ADI_DEV_MODE_CHAINED },

{ ADI_UART_CMD_SET_DATA_BITS,           (void *)DATA_BITS_COUNT      },

{ ADI_UART_CMD_ENABLE_PARITY,           (void *)PARITY                  },

{ ADI_UART_CMD_SET_STOP_BITS,           (void *)STOP_BITS_COUNT      },

{ ADI_UART_CMD_SET_BAUD_RATE,           (void *)BAUD_RATE              },

{ ADI_DEV_CMD_END,                       NULL                            },

};

 

 

Result = adi_dev_Open(DevMgrHandle,&ADIUARTEntryPoint,0, (void *)0x12345,&UARTHandle,

               ADI_DEV_DIRECTION_BIDIRECTIONAL, NULL, NULL, UARTCallbackFunction);

 

Result = adi_dev_Control(UARTHandle,ADI_DEV_CMD_TABLE,UARTConfiguration);

 

UARTInboundBuffer.Data              = InboundData;

UARTInboundBuffer.ElementCount      = ELEMENT_COUNT;

UARTInboundBuffer.ElementWidth      = ELEMENT_WIDTH;

UARTInboundBuffer.CallbackParameter = (void *)0;

UARTInboundBuffer.pNext             = NULL;

UARTInboundBuffer.pAdditionalInfo   = (void *)0;

 

UARTOutboundBuffer.Data              = OutboundData;

UARTOutboundBuffer.ElementCount      = ELEMENT_COUNT/2;

UARTOutboundBuffer.ElementWidth      = ELEMENT_WIDTH;

UARTOutboundBuffer.CallbackParameter = (void *)1;

UARTOutboundBuffer.pNext             = NULL;

UARTOutboundBuffer.pAdditionalInfo   = (void *)0;

 

Result = adi_dev_Read(UARTHandle,ADI_DEV_1D, (ADI_DEV_BUFFER *)&UARTInboundBuffer);

 

Result = adi_dev_Control(UARTHandle,ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE);

 

}

 

/*********************************************************

/*     Function: UART_WriteData

/*     Description: write data to uart device

/********************************************************/

static void UART_WriteData(unsigned char * data,unsigned char len)

{

unsigned char i;

 

if (len>ELEMENT_COUNT/2) return;

for (i=0;i<len;i++) UARTOutboundData[i]=data[i];

 

adi_dev_Write(UARTHandle,ADI_DEV_1D, (ADI_DEV_BUFFER *)&UARTOutboundBuffer);

}

 

/*********************************************************

/*     Function: Callback

/*     Description: Callback for input data

/********************************************************/

static void UARTCallbackFunction(void *ClientHandle, u32 Event, void *pArg)

{

 

char BufferType = (char)pArg;

 

if ((Event==ADI_DEV_EVENT_BUFFER_PROCESSED)&&(BufferType==0)) ProcessCommandFromTube();

 

adi_dev_Read(UARTHandle,ADI_DEV_1D, (ADI_DEV_BUFFER *)&UARTInboundBuffer);

 

}

Attachments

Outcomes