|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#7
|
|||||
|
|||||
|
Re: Using the TTL port
Astronouth7303,
Here is the code we used to talk to a second micro that was keeping track of our position. It uses the TTL port. The documentation supplied didn't mention setting the port directio registers (See the first couple of lines in the SensorInitializePort() routine). The EDU Bot did it for you but the RC requires that you do it yourself. If you want the source files PM me and I'll email you the files. Gene F. Team 343 Metal in Motion AAARRRGGG!!! The tabs all got removed when I posted the code! If anyone needs/wants the actual source code PM me. #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) { // Set up TX pin as an output and RX as an input. TRISGbits.TRISG1 = 0; TRISGbits.TRISG2 = 1; 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 < 2500; i++ ) if ( DataRdy2USART()) break; // If a character arrived (we didn't timeout) if ( i != 2500 ) { // Grab the next charcter from the USART and 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()); /* printf EXAMPLE */ } } RCSTA2bits.CREN = 0; // Disable the receiver // printf("x=%6d,y=%6d,pe=%6d,dd=%4d,ae=%4d\n", Sensors.LeftOdom, Sensors.RightOdom, Sensors.PosError, (int)(unsigned char)Sensors.DDCompass, (int)( char)Sensors.AngleError ); } /************************************************** ***************************** * FUNCTION NAME: ensorEnterAutoMode * PURPOSE: Puts the sensor pack into automatic mode sending the desired x * and y coordiantes. * Format of command: A<xl><xl><yl><yh> * CALLED FROM: user_routines.c * ARGUMENTS: none * RETURNS: void ************************************************** *****************************/ void SensorEnterAutoMode (int x, int y) { volatile int i; printf("x=%d y=%d\r",x,y); while (Busy2USART()); putc2USART('A'); for(i=0;i<1000;i++); while (Busy2USART()); putc2USART((char)(x & 0xff)); for(i=0;i<1000;i++); while (Busy2USART()); putc2USART((char)((x >> 8) & 0xff)); for(i=0;i<1000;i++); while (Busy2USART()); putc2USART((char)(y & 0xff)); for(i=0;i<1000;i++); while (Busy2USART()); putc2USART((char)((y >> 8) & 0xff)); for(i=0;i<1000;i++); while (Busy2USART()); putc2USART('\0'); } |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Having trouble with TTL port | Gene F | Programming | 12 | 10-02-2004 15:23 |
| TTL pins | Dave... | Control System | 3 | 07-02-2004 23:59 |
| 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 |