CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

16F628 RS232 not transmitting or receiving.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

16F628 RS232 not transmitting or receiving.
PostPosted: Tue May 25, 2004 12:23 pm     Reply with quote

Hello, forum:

I am using v3.178 on a 16LF628. I am trying to send data on the RS232 to communicate between the PIC and a GPS unit. The hardware is fine - whilst monitoring the wires, I can see that the GPS unit is sending its default set of strings.

However, I can't get the chip to send the string to request the non-default data. Previous versions of the code (which are unreadably obfuscated) were able to send and receive the required information.

This leads me to believe that the problem is a PEBKAS error. (Problem exists between keyboard and seat.) I've clearly not set some critical value somewhere. My question is, what's that missing setting?

Thank you for your help.

Code:


#define GGA_REQUEST "$PXEMSNM,0001,01*50"

int1 get_GPS_fix( struct GPS_data * G_P_S )
{
  int1 got_fix = false;
  #use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, RESTART_WDT)
  //Set the output pins to output.
  TRIS_B = 0b10001011; // PORT B.2 RS232_XMT, B.4 TX_ON, B.5 PHASE_1
                       // B.6 PHASE_2 are outputs. PORT_B.0 TIMEBASE,
                       // B.1 RS232_RCV, B.3 MORT_IO, B.7 RTS are IN.
  PORT_B = 0b01100000; // PORT B.2 RS232_XMT = 0 (idle state for GPS
                       // interface), B.3 PLL_ON = 0 (xmtr PLL off),
                       // B.4 TX_ON = 0 (xmtr off), B.5 PHASE_1 = 1
                       // & B.6 PHASE_2 = 1 (xmtr modulator phase
                       // controls inactive), all other pins are IN
  // Power up the GPS engine.
  GPS_ON = HIGH;
  // Wait for GPS engine to power up (250ms is marginal).
  delay_ms( 1000 );
  //Wait for the GGA request to clear, then wait for the GGA data
  //to come back. Do nothing until then.
  if( send_request( GGA_REQUEST ) )
  { //do something }
  //A *LOT* more code goes here, but it's not important.
}

// Sends the NMEA string $PXEMSNM,0001,01*50 (followed by <CR> <LF>)
// which sets up the Xemics GPS module to send GGA data every second.
// Note - strings are hard coded, because of lack of memory space.
int1 send_request( char request[19] )
{
  int1 return_value = false;
  putc(0); // Send a dummy character to flush out the GPS uart.
  putc(0);
  putc(0);
  putc( request );
  putc(13); //CR
  putc(10); //LF

  //The return and line feed are automatically sent with puts().
  return_value = true;
  return( return_value );
}



PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 25, 2004 1:48 pm     Reply with quote

My suggestion is to always keep things simple.
If you just want to send that string, here is a routine that will do it.

Code:
char send_request(void)
{
 putc(0); // Send 3 dummy chars to flush GPS USART.
 putc(0);
 putc(0);

 puts("$PXEMSNM,0001,01*50");   // Send string, followed by CRLF.

 return(TRUE);
}
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

PostPosted: Tue May 25, 2004 3:03 pm     Reply with quote

Thanks, PCM. I tried that, but I'm still not transmitting. There's no activity on the transmit pin, and the GPS keeps sending out its default messages.

The reason I didn't hardcode in the message in that function is because I call it three times. That's in the code that I didn't include.

PCM programmer wrote:
My suggestion is to always keep things simple.
If you just want to send that string, here is a routine that will do it.

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 25, 2004 3:18 pm     Reply with quote

If it's not transmitting, then create a simple test program,
such as the following one. Run this program, and then
look at pin B2 for activity. (Change the oscillator fuse,
clock speed, and baud rate as required for your proto board).

Code:
#include <16F628.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP 
#use Delay(Clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS) 

//=========================================
void main(void)
{

while(1)
  {
   putc(0x55);
  } 

}
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

PostPosted: Tue May 25, 2004 5:13 pm     Reply with quote

PCM:

The test program is working. After changing it to send out the request ( "$PXEMSNM,0001,01*50" ), I get the expected return string on the RS232 recieve pin. I had to put in a bit of a delay to prevent gibberish, but I am getting the correct data.

To me, this says that I'm not getting to the function. It's nice to know that I did get the RS232 settings set properly.

Thanks for your help.

PCM programmer wrote:
If it's not transmitting, then create a simple test program,
such as the following one. Run this program, and then
look at pin B2 for activity. (Change the oscillator fuse,
clock speed, and baud rate as required for your proto board).
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed May 26, 2004 7:25 am     Reply with quote

Quote:

This leads me to believe that the problem is a PEBKAS error. (Problem exists between keyboard and seat.)


Regarding the PEKBAS, Very Happy you just post a couple of functions out of context. In this way I can�t see how they works. Pls drop the relevant code in main() regarding how such functions are called.

Humberto
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

PostPosted: Wed May 26, 2004 11:11 am     Reply with quote

Humberto:

For testing, I've modified main so it's as listed below. I'm using the serial port monitor to figure out what's going on in the circuit. It's transmitting just fine, but I think it's not receiving. (The "putc(timed_getc());") plan is giving the timeout character.)

Code:

main()
{
  struct GPS_data GPS;
  do //superloop
  {
    if( get_GPS_fix( &GPS )
    {
      // do nothing;
    }
  }while(true);
}

Humberto wrote:
Quote:

This leads me to believe that the problem is a PEBKAS error. (Problem exists between keyboard and seat.)


Regarding the PEKBAS, Very Happy you just post a couple of functions out of context. In this way I can�t see how they works. Pls drop the relevant code in main() regarding how such functions are called.

Humberto
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

PostPosted: Wed May 26, 2004 12:33 pm     Reply with quote

It's funny how the manual doesn't say that you should include the "ERRORS" option in the list of options. I put it in, and I was able to start receiving.

Thanks for your help, guys.
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Wed May 26, 2004 1:13 pm     Reply with quote

theMagni wrote:
It's funny how the manual doesn't say that you should include the "ERRORS" option in the list of options. I put it in, and I was able to start receiving.

Thanks for your help, guys.


I found that the manual really needs updating by someone who did not write the compiler so the obvious stuff( to the compiler writers) is included
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group