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

usart_receiving & sending byte array

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



Joined: 25 Jun 2008
Posts: 3

View user's profile Send private message

usart_receiving & sending byte array
PostPosted: Wed Jun 25, 2008 2:13 am     Reply with quote

i've searched the forum but could not understand how to send byte array to PC.

i have a byte array defined as
Code:
int8 pr[8]

I use Visual Basic at PC side to receive and send the array values.

Is there a basic sample code that implements sending&receiving byte arrays?

best regards
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Wed Jun 25, 2008 8:05 am     Reply with quote

C:\Program Files\PICC\Examples\EX_SISR.C
C:\Program Files\PICC\Examples\EX_STISR.C
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Jun 25, 2008 8:13 am     Reply with quote

You have to loop through the array and send it a byte at a time...
Guest








PostPosted: Wed Jun 25, 2008 11:36 pm     Reply with quote

I've managed to send byte array by using for loop
Code:
for(i=0;i<=7;i++)
{
putc(pr[i]);
}


In the program, serial port setting is defined as
Code:
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7, PARITY=N, BITS=8, STOP=1)


And here is my serial interrupt routine:
Code:

#int_rda
void rda_isr(void)
{
   int i;
   for(i=0;i<5;i++)
   {
      output_high(LED);
      delay_ms(200);
      output_low(LED);
      delay_ms(200);
   }
}


I just wanted to see that this code block works or not. So i've tried to flash the LED when receiving data from PC. But there is no "change" on the LED status. I also tried to disable and then enable INT_RDA in the interrupt service routine but there is no change. I think this interrupt routine does not work. Am i doing something wrong?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Thu Jun 26, 2008 6:34 am     Reply with quote

You won't get any int_rda interrupts unless you enable them in your main program setup. They are not automatically enabled by the #use rs232 directive. The standard CCS library function for rs232 receive uses polling. And if you ever do get an int_rda interrupt, you need to handle it and return quickly. Don't spend any significant time in the interrupt routine. Your "testing" code would probably work and flash the LED the first time, but all subsequent characters received during your LED flashing time will be lost. Also you must read the RCREG somewhere inside your int_rda or else that interrupt will not ever get acknowledged and it will keep interrupting over and over. Why do you want to use interrupts anyway? Does your application require that many input characters be buffered by interrupts before your main program can get around to reading them? If your main program can poll often enough, you don't need to use interrupts.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Guest








PostPosted: Thu Jun 26, 2008 6:39 am     Reply with quote

I've enabled int_rda interrupt in the beginning of the program.

It is an motor control program and these bytes are parameters for the driver.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jun 26, 2008 7:09 am     Reply with quote

Have you got
enable_interrupts(INT_RDA); // and
enable_interrupts(GLOBAL); // ?

What is your pic connected to serially ?
What are you expecting from the serial port ?

You won't get an interrupt unless something comes in over the serial port!
sdonmez



Joined: 25 Jun 2008
Posts: 3

View user's profile Send private message

PostPosted: Fri Jun 27, 2008 1:06 am     Reply with quote

there is an interesting problem!
here is the code.
Code:
#int_rda
void rda_isr(void)
{
   char b;
   disable_interrupts(INT_RDA);
   output_toggle(LED);
   putc('*');
   j=RCREG;
   enable_interrupts(INT_RDA);
}


When i send a character from hyperterminal, LED toggles but PIC does not send "*" back to hyperterminal.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Fri Jun 27, 2008 7:31 am     Reply with quote

do no do disable_interrupts(INT_RDA); or enable_interrupts(INT_RDA); inside the ISR
It is done for you.
Code:
#int_rda
void rda_isr(void)
{
   j=RCREG; 
   output_toggle(LED);
   putc('*');
}
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