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

18f252 rs232 int_rda problem

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



Joined: 23 May 2007
Posts: 81

View user's profile Send private message

18f252 rs232 int_rda problem
PostPosted: Wed May 23, 2007 1:37 pm     Reply with quote

Hi all,
I've connected 18F252 with max232 to PC, when the first power came; 3 unlikely interrupts show up, and then when i try to send something from hyperterminal (or terminal or Docklight) ,there is no interrupt so it doesn't take any data, it sends data but it doesn't take back.

i did the similar work before with 16 series Pics and they work good.What kind of differences can be on F252, What am i suppose to do about it ?

Code is here:
Code:
#include <18F252.h>
#device   *=16 adc=10
#FUSES NOWDT,HS,NOPROTECT,NOOSCSEN,BROWNOUT,NOPUT,STVREN
,NODEBUG,NOLVP,NOWRT,NOWRTD,NOWRTB,NOWRTC,NOCPD,NOCPB,
NOEBTR,NOEBTRB

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#priority   RDA

#byte   PORTC          = 0xF82
#byte   PORTB          = 0xF81
#byte   PORTA          = 0xF80

#bit   BusyLED   =   PORTB.4

#int_RDA
void RDA_isr() {
   putc(getc());
   printf("int_RDA\n");
}

void main()   {
    //setup_adc_ports(AN0_VREF_VREF);
    //setup_adc(ADC_CLOCK_DIV_64);
    setup_spi(FALSE);
    setup_wdt(WDT_OFF);
    SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_1);
    SETUP_TIMER_1(T1_DISABLED);                      //   Disable   Timer   1
    SETUP_TIMER_2(T2_DISABLED,   127, 1);          //   Disable   Timer   2
    SETUP_TIMER_3(T3_DISABLED);                      //   Disable   Timer   3
    SETUP_CCP1(CCP_OFF);                                  //   Disable   CCP1
    SETUP_CCP2(CCP_OFF);                                  //   Disable   CCP2
    SET_TRIS_A(0b00001111);
    SET_TRIS_B(0b00000100);
    SET_TRIS_C(0);
    PORTA = 0;
    PORTB = 0;
    PORTC = 0;
    BusyLED=1;
    enable_interrupts(INT_RDA);
    enable_interrupts(GLOBAL);
    delay_ms(200);
    printf("Start\n");
    for(;;) {
          ;
    }
}


Help please.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2007 1:54 pm     Reply with quote

1. Add the 'ERRORS' parameter to your #use rs232() statement.

2. Don't put a printf() inside your #int_rda routine. It takes too long
to send all those bytes. It blocks rda interrupts from being processed
while it is sending those bytes. If interrupts are blocked, the incoming
bytes can't be removed from the UART receiver. It will then get an
overrun error. Without the ERRORS statement, the overrun error
will cause the UART receiver to lock-up. It won't work.
tesla80



Joined: 23 May 2007
Posts: 81

View user's profile Send private message

PostPosted: Wed May 23, 2007 3:02 pm     Reply with quote

Thanks,
Added errors but show up a warning (variable never used : rs232_errors)
Code:
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS,restart_wdt)


in int_rda:
Code:
#int_RDA
void RDA_isr() {
   S=getc();
}


in main
Code:
if(S=='p') printf("ok\n");


but still it doesn't work.
i apply on rx and tx pins 5V, but doesn't interrupt...

and schema :
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2007 3:38 pm     Reply with quote

Try the simple program shown at the end of this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=30380
tesla80



Joined: 23 May 2007
Posts: 81

View user's profile Send private message

PostPosted: Wed May 23, 2007 4:35 pm     Reply with quote

it's working with your code
Code:
#include <18F252.h>
#fuses HS, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#int_rda
void rda_isr(void)
{
char c;

c = getc();   // Get character from PC

putc(c);    // Send it back to the PC
}   

//========================
void main()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

while(1);
}

what is the difference? fuses?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2007 4:42 pm     Reply with quote

You have TRISC.7 (Rx) set incorrectly. You're setting it as an output
and it must be set as an input pin.
tesla80



Joined: 23 May 2007
Posts: 81

View user's profile Send private message

PostPosted: Wed May 23, 2007 4:52 pm     Reply with quote

yes, you are right. I wouldn't think this.

SET_TRIS_C(0b10000000);
TRISC=0x80;
Thanks, it's working good now! Smile
sella
Guest







PostPosted: Mon Jul 21, 2008 6:24 pm     Reply with quote

I'm doing a RF project using PIC18F252 as the receiver.There are 1 transmitter and 2 receivers. When i use the sample program EX_SISR.C, the data sent was received and displayed in virtual terminal. I need to use the received data to compare with another data to detect either it is same with receiver 1 or receiver 2.Then LED at receiver 1 or receiver 2 must be on.But now i am not able to compare the data.
Below are the sample code.
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#elif defined(__PCH__)

#include <18F252.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif
#include <string.h>

#define G1_LED PIN_B2
#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr() {
int t;

buffer[next_in]=getc();
t=next_in;
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() {

char Temp_Data;
char string[10]= "THSW1";

enable_interrupts(global);
enable_interrupts(int_rda);

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

// The program will delay for 10 seconds and then display
// any data that came in during the 10 second delay

do {
delay_ms(10000);
while(bkbhit)

putc( bgetc() );
Temp_Data = bgetc();

if(strcmp(Temp_Data,string)==0)

{
output_high (G1_LED);
delay_ms(60000);
}

}while (TRUE);
}
I really need help here. This is my final year project...
Kindly please help me.
thanks
Ttelmah
Guest







PostPosted: Tue Jul 22, 2008 2:29 am     Reply with quote

A a comment, the 'variable never used RS232_ERRORS' warning, is just an annoyance of the compiler, and remember is only a _warning_. It does not in itself imply that anything is really wrong, it is just telling you this, so that if it is a variable that isn't used, you can possibly get rid of it, and save a small amount of RAM
If you add the 'errors' statement to the RS232 setup (which should be the default), the compiler does two things. First it adds to the getc code, routines to clear errors if set. Then it generates a variable called 'RS232_ERRORS', and when it clears an error, makes a copy of the error bits into this. Hence you can at any time read this variable, and see what the last error was. However if you don't read the variable, you get the warning, which 'worries' some people, who don't understand what is happening.

Best Wishes
sella
Guest







PostPosted: Tue Jul 22, 2008 7:44 am     Reply with quote

Hi! Thanks for the reply.
I tried to compare the data received with another data, but I still couldn't get the output desired. I can't understand why the data is not compared.
Please kindly reply.
thanks
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