View previous topic :: View next topic |
Author |
Message |
sdonmez
Joined: 25 Jun 2008 Posts: 3
|
usart_receiving & sending byte array |
Posted: Wed Jun 25, 2008 2:13 am |
|
|
i've searched the forum but could not understand how to send byte array to PC.
i have a byte array defined as
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
|
|
Posted: Wed Jun 25, 2008 8:05 am |
|
|
C:\Program Files\PICC\Examples\EX_SISR.C
C:\Program Files\PICC\Examples\EX_STISR.C |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Wed Jun 25, 2008 8:13 am |
|
|
You have to loop through the array and send it a byte at a time... |
|
|
Guest
|
|
Posted: Wed Jun 25, 2008 11:36 pm |
|
|
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
|
|
Posted: Thu Jun 26, 2008 6:34 am |
|
|
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
|
|
Posted: Thu Jun 26, 2008 6:39 am |
|
|
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
|
|
Posted: Thu Jun 26, 2008 7:09 am |
|
|
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
|
|
Posted: Fri Jun 27, 2008 1:06 am |
|
|
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
|
|
Posted: Fri Jun 27, 2008 7:31 am |
|
|
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('*');
} |
|
|
|
|