Go to Post ...the great teams in FRC will probably continue to be great teams. That is because they have great people who embrace the challenge rather than whine about it. - dtengineering [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 06-02-2004, 10:05
Gene F's Avatar
Gene F Gene F is offline
FIRST Fanatic
AKA: Gene Falendysz
#0343 (Metal in Motion)
Team Role: Engineer
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Oconee County, SC
Posts: 218
Gene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to behold
Send a message via AIM to Gene F
Having trouble with TTL port

I have written the following code for talking to the TTL port. When I run the code on the EDUBot it works great I then try it on the Robot controller and I don't get any characters coming in. I have placed my SensorInitializePort() in the User_Initialization () routine and my SensorPackRead () routine in the Default_Routine() in the respective projects.

Note: If this is hard to read because of the tabs being removed by the forum I have attached the files in word format.
// Definition of the data structure and routines for reading the sensor pack

#ifndef __sensors_h_
#define __sensors_h_

#define STX (0x02)

typedef union
{
struct Data_tag
{
short xPos;
short yPos;
short PosError;
unsigned char DDCompas;
char AngleError;
unsigned char NullByte;
};
char chars[9];
} SensorPackType;

extern SensorPackType Sensors;

void SensorInitializePort (void);
void SensorPackRead (void);



#endif







#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "sensors.h"
#include "printf_lib.h"
// Added by Gene
#include <usart.h>
#include "delays.h"

SensorPackType Sensors;

/************************************************** *****************************
* FUNCTION NAME: InitializeSensorPort
* PURPOSE: Opens the serial port 2 for communicating with the scensors at
* 19.2k baud, 8 bits, no parity, one stop bit, and no flow control.
* CALLED FROM: user_routines.c
* ARGUMENTS: none
* RETURNS: void
************************************************** *****************************/
void SensorInitializePort (void)
{
Open2USART(USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
128);

Delay1KTCYx( 50 ); /* Settling time */
}

/* Code to read Bills device. */
/************************************************** *****************************
* FUNCTION NAME: ReadSensorPack
* PURPOSE: Talks to the sensor pack to read the current data
* CALLED FROM: user_routines.c
* ARGUMENTS: none
* RETURNS: void
************************************************** *****************************/
void SensorPackRead (void)
{
int i, j;
RCSTA2bits.CREN = 1; // Re-enable the receiver
// Send an STX to the sensor pack to tell it to send the data
putc2USART(STX);

// Loop for the number of characters in the sensor pack data
for ( j = 0; j < 8/*sizeof(SensorPackType)*/; j++ )
{
// Wait a finite amount of time for the next character to arrive.
for ( i = 0; i < 20000; i++ )
if ( DataRdy2USART())
break;

// If a character arrived (we didn't timeout)
if ( i != 20000 )
{
// Grab the next charcter from the USART ant place it in our data structure
Sensors.chars[j] = getc2USART();
}
else
{
// If it failed then clear any possible errors
RCSTA2bits.CREN = 0; // Disable the receiver
RCSTA2bits.CREN = 1; // Re-enable the receiver
printf("Rx Fail DataRdy = %d\n",(int)DataRdy2USART());
}
}
RCSTA2bits.CREN = 0; // Disable the receiver
printf("x=%6d,y=%6d,pe=%6d,dd=%4d,ae=%4d\n",
Sensors.xPos,
Sensors.yPos,
Sensors.PosError,
(int)(unsigned char)Sensors.DDCompas,
(int)( char)Sensors.AngleError );

}
Attached Files
File Type: doc Sensor.doc (26.0 KB, 54 views)
__________________
- Gene Falendysz
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone else having trouble keeping up with work? D. Gregory General Forum 36 28-03-2004 16:55
Win32 serial port - recieve buffer seanwitte Programming 4 05-11-2003 21:41
Fried program slots? Jeff Waegelin Programming 18 19-03-2003 18:08
Dashreader.dll: A Visual Basic .NET user control to read the dashboard port Ameya Programming 4 12-01-2003 23:40
Change to Initializing Inputs and Outputs Jferrante Programming 4 07-01-2003 11:36


All times are GMT -5. The time now is 17:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi