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

Pic 18F2520 rs232

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



Joined: 02 Jan 2006
Posts: 75
Location: Neeroeteren, Limburg, Belgium

View user's profile Send private message

Pic 18F2520 rs232
PostPosted: Thu Apr 17, 2008 8:26 am     Reply with quote

Hello to you all,

I am working on a new pic at the moment.

PIC18F2520

Now i want to communicate with this device, using RS232.

I made a USB interface with a USB<->RS232 convertor.
And a small PC program tot communicate with the Pic

I have basically the same code running on a 18F242.

here is a short testing version:

Code:

#include <18F2520.h>
#device ADC=10
#include <stdlib.h>
#fuses HS, NOWDT, PUT, BORV27, NOLVP, EC_IO, NOSTVREN, NODEBUG, PROTECT, MCLR  //, EBTR
#org 190, 8190 {}

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use delay (clock=20000000)
#use rs232 (baud=19200, xmit=PIN_C6, rcv=PIN_C7)

#define LED PIN_C3      // LED

int int_a, rs_pnt;
char rs_in[10];
boolean bl_ok;

#INT_RDA
void serial_isr();

#separate
void blink_fast();
#separate
void blink_slow();

#INT_RDA
void serial_isr()
{
   char a;
   a = getc();

   printf("ok");
   bl_ok = !bl_ok;
}

#separate
void blink_fast()
{
   output_high(LED);
   delay_ms(5);
   output_low(LED);
   delay_ms(5);
}

#separate
void blink_slow()
{
   output_high(LED);
   delay_ms(25);
   output_low(LED);
   delay_ms(25);
}


#separate
void main(void)
{

int_a = 0;
bl_ok = 0;
rs_pnt = 0;
set_tris_c(129);
SETUP_ADC_PORTS(NO_ANALOGS);
output_low(LED);

enable_interrupts(GLOBAL);

enable_interrupts(INT_RDA);

while(1)
   {
      if(bl_ok)
         blink_fast();
      else
         blink_slow();
   }
}



On the 242 I allways get the "ok" message on my screen when i send something over.
On the 2520, nothing happens.

also, i tried in the int_rda code:
Code:

        char a;
   a = getc();
        if (a == '#')
   printf("ok");

        bl_ok = !bl_ok;


when i send # my LED blinking speed changes every time i send it again, so it seems the 2520 receive some data.

but whin i apply this code:
Code:
if (a == '#')
bl_ok = !bl_ok;

my LED speed stays the same.

Also i am not getting anything from the pic.

The pin occupation of 242 and 2520 are the same for my app.

I also tried using a stream etc at the rs232 setup.


Is there any change in the 2520 i am not aware of?

Thanks a lot!

Blob
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Apr 17, 2008 8:52 am     Reply with quote

Most would never put a printf in an isr. It may not be your problem but it will in time eventually bite you. Look at circular buffers and read this forum for this kind of issue has been asked and answered very very many times.
Blob



Joined: 02 Jan 2006
Posts: 75
Location: Neeroeteren, Limburg, Belgium

View user's profile Send private message

PostPosted: Fri Apr 18, 2008 1:00 am     Reply with quote

Hello Douglas,

you are right i should have searching a bit harder.

I found the problem!

It was a wrong interpretation of the fusebits...

i did set EC_IO => external clock.
but i us a 20 MHz Xtal....

So i should only set HS, not HS and EC_IO...


I saw the problem when i was thinking my led blinks too slow for intervals of 5 or 25 ms...


Best Regards,

Blob
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