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 support@ccsinfo.com

RS-232 headaches INT_EXT versus INT_RDA

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







RS-232 headaches INT_EXT versus INT_RDA
PostPosted: Thu Jan 17, 2008 7:13 pm     Reply with quote

I have set up a board, running at 20MHz, with two RS232 ports: one on the UART (C7/C6) and one to use the EXT interrupt (B0/B1). I am using CCS sample code basically. Receive data on one port, buffer, and retransmit on the same port. By changing the DEFINE at the top of the program, one can select between the UART and the S/W port.

The UART version works great. The S/W version does not. The output is jbberish.

By setting a breakpoint and watching the buffer data, I can see that the corruption of data seems to be happening upon receipt. The S/W output seems to mimic whatever is in the buffer.

I need both ports running at 4800 baud (GPS application). Eventually, once I solve this problem, I intend to use two RS-232 ports at once. The processor is the 16F737 and it is running on a crystal at 20MHz. (At least I think I have told the compiler to use the crystal)...

Can anyone see what is wrong here? THANKS!!!

/////////////////////////////////////////////////////////////////////////
//// Buffered Serial Input/output ////
//// ////
//// pick between software (IND_EXT) B0/B1 or UART (INT_RDA)C7,C7 ////
//// ////
//// CHARACTERS BEING CORRUPTED UPON RECEIPT DURING INT_EXT ////
//// RECEIPT -- WORKS PERFECTLY USING INT_RDA ////
//// ////
/////////////////////////////////////////////////////////////////////////


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// CHANGE MODES BY COMMENTING IN OR OUT THE FOLLOWING LINE
#define USE_EXT // use S/W RS232, comment out to use RDA (UART) port instead
//
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

#include <16F737.h>

#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)

#if defined(USE_EXT)
#use rs232(baud=4800, xmit=PIN_B1, rcv=PIN_B0, parity=N, BITS = 8, stop=1) //, disable_ints)
#else // use RDA
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, parity=N, BITS = 8, stop=1)
#endif

// Initialize Buffer
#define BUFFER_SIZE 64
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

// Set up serial interrupt
#if defined (USE_EXT)
#int_ext
#else
#int_rda
#endif

void serial_isr() {
int t,x;

buffer[next_in]=getc();
t=next_in;
if (t==32) // just for breakpoint
x=t;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
BYTE c;

while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % BUFFER_SIZE;
return(c);
}

void main() {

#if defined (USE_EXT)
enable_interrupts(int_ext);
#else
enable_interrupts(int_rda);
#endif

enable_interrupts(global);

printf("\r\n\Running...\r\n");

do {
if(bkbhit) {
putc(bgetc());
}
} while (TRUE);
}
peteD



Joined: 22 May 2006
Posts: 5

View user's profile Send private message

Additional Information
PostPosted: Thu Jan 17, 2008 7:38 pm     Reply with quote

Board: Olimex PIC-28 schematic is here: http://www.olimex.com/dev/images/PIC/PIC-P28-sch.gif (I am using two extra ports of MAX232 for the B0/B1 RS-232 port).

Compiler: 4.064

IDE: MPLAB 8.00.000
peteD



Joined: 22 May 2006
Posts: 5

View user's profile Send private message

definitely not a hardware problem...
PostPosted: Thu Jan 17, 2008 8:05 pm     Reply with quote

If I remove the PIC from the board and jumper B1 and B0 pins together, the data moves through and the output is clean. This eliminates the MAX232 as a possible problem. All it could be in my mind is timing, but how come I can't get even the simplest of software rs232 repeaters to run without having the input corrupted???

such as this:

#include <16F737.h>
#fuses HS,NOWDT
#use delay(clock=20000000)
#use rs232(baud=4800, xmit=PIN_b1, rcv=PIN_b0, ERRORS)

//================================
void main(void)
{
char c;

while(1)
{
c = getc();
putc(c);
}

}
Guest








No one has a clue?
PostPosted: Fri Jan 18, 2008 8:29 am     Reply with quote

46 people have viewed this problem but not one person has a clue on the problem?
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jan 18, 2008 8:36 am     Reply with quote

Code:
void main(void)
{
   char c;

   while(1)
   {
       while(!kbhit());      // try adding this
       c = getc();
       putc(c);
    }

}


I've used the 'software UART' but wait for an incoming char with kbhit - CCS manul says getc *should* wait, but worth a try
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 18, 2008 11:51 am     Reply with quote

Quote:
46 people have viewed this problem but not one person has a clue on the problem?

A lot of these 46 people are students. Some of them are 'bots like
Google, scanning the board. While you are making this post, half the
board is still asleep or just getting up in the morning.


Quote:
#use rs232(baud=4800, xmit=PIN_b1, rcv=PIN_b0, ERRORS)

while(1)
{
c = getc();
putc(c);
}

I need both ports running at 4800 baud (GPS application).

The (hardware) UART version works great. The S/W version does not. The output is jibberish.

Be aware that CCS is doing the most simple type of software UART.
Of the three methods listed on this webpage, CCS is doing #3:
http://www.8052.com/faqs.phtml?FAQ=124758

Iif you have a continuous stream of incoming bytes with no gap
between them, the CCS-type of software UART will fail. While it's
doing the putc(), it can't be doing the getc(). You will lose a character.
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jan 18, 2008 12:22 pm     Reply with quote

Quote:
Iif you have a continuous stream of incoming bytes with no gap
between them, the CCS-type of software UART will fail. While it's
doing the putc(), it can't be doing the getc(). You will lose a character.


Very true - I should have added that I only use the software UART for human command interfaces, where the chars will come in slowly.
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