I have written a code to read data from serial port. The data being sent is 12 bytes long with first 6 bytes as header. The code works and displays the correct data (shown below)
Code: Select all
///included
#include "predef.h"
#include <stdio.h>
#include <stdlib.h>
#include <basictypes.h>
#include <ucos.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <taskmon.h>
#include <smarttrap.h>
#include <effs_fat/fat.h>
#include <effs_fat/multi_drive_mmc_mcf.h>
#include <effs_fat/effs_utils.h>
#include <sim.h>
#include <pins.h>
#include <ucosmcfc.h>
#include <pinconstant.h>
#include <HiResTimer.h>
#include <utils.h>
#include <constants.h>
#include <cfinter.h>
#include <math.h>
#include <serial.h>
#define header1 0xAAAA
#define header2 0xABAB
#define header3 0xBBBB
//Global Variables
extern "C"
{
void UserMain( void * pd);
void SetIntc( int intc, long func, int source, int level);
}
void initPINS()
{
J2[15].function(0);
J2[15]=0;
J2[39].function(2);//RX 8
J2[42].function(2);//TX 8
}
void UserMain( void* pd )
{
/////Usual Routine
InitializeStack();
OSChangePrio( MAIN_PRIO );
EnableAutoUpdate();
EnableTaskMonitor();
EnableSmartTraps();
//Initializing
initPINS();
char input_buff[6];
char hdr1[2];
char nxt_hdr[4];
uint16_t header_buff[3]={0,0,0};
int16_t data[3];
int fdSerial;
int fdSerial2;
SerialClose(0);
SerialClose(8);
fdSerial2=OpenSerial( 0, 115200, 1, 8, eParityNone );
fdSerial = OpenSerial( 8, 115200, 1, 8, eParityNone );
while(1)
{
OSTimeDly(1);
J2[15]=J2[15]^J2[15];
read(fdSerial,(char*)hdr1,2);
header_buff[0]=(uint16_t)((uint8_t)hdr1[0])*256+(uint8_t)hdr1[1];
if(header_buff[0]==0xAAAA)
{
read(fdSerial,(char*)nxt_hdr,4);
header_buff[1]=(uint16_t)((uint8_t)nxt_hdr[0])*256+(uint8_t)nxt_hdr[1];
header_buff[2]=(uint16_t)((uint8_t)nxt_hdr[2])*256+(uint8_t)nxt_hdr[3];
if(header_buff[1]==0xABAB && header_buff[2]==0xBBBB)
{
read(fdSerial,(char*)input_buff,6);
data[0]=(int16_t)((uint8_t)input_buff[0])*256+(uint8_t)input_buff[1];
data[1]=(int16_t)((uint8_t)input_buff[2])*256+(uint8_t)input_buff[3];
data[2]=(int16_t)((uint8_t)input_buff[4])*256+(uint8_t)input_buff[5];
printf("%d %d %d\n",data[0],data[1],data[2]);
}
}
}
}
1)Their is a huge delay between the time when data is being transmitted and the time when data is displayed on MTTTY screen (more than 10 seconds)
2)The code doesn't work if I remove "OSTimeDly(1)" in the while loop.
I am assuming that serial port 0 and serial port 8 are interfering with each other. Any comments and suggestions are welcome.
Thanks in advance,
TM