![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
hayy Guest
|
serial interrupt |
Posted: Mon Oct 17, 2005 3:19 am |
|
|
i am having a few diffucilties in serial_isr. pic cannot receive serial data because the serial_isr doesnt work.. here is the code. what is missing?
Code: |
#include <16F877.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,XT, PUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,FORCE_SW)
//#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
int index=0;
byte buffer[2];
#int_RDA
void serial_isr()
{
//output_high(pin_D2);
buffer[index]=getch();
index++;
if (index==2) index=0;
}
void main()
{
int i=0;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_b(0);
output_b(0);
set_tris_d(0);
output_d(0);
for(i=0;i<3;i++)
buffer[i]=0;
index=0;
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1)
{
output_b(buffer[0]);
output_d(buffer[1]);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Oct 17, 2005 3:40 am |
|
|
You cannot have a serial interrupt with a software UART...
Get rid of the 'force_sw' in the port setup. Also add 'errors', which will stop the port locking up if data is not processed fast enough.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
hayy Guest
|
|
Posted: Mon Oct 17, 2005 4:53 am |
|
|
additions are made but no action yet ![Sad](images/smiles/icon_sad.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Oct 17, 2005 5:12 am |
|
|
Though it should work, the problem may be that the code as written is just missing the interrupts. You are accessing the array continuously in the external loop, which will imply that interrupts are disabled for this access (since the array is also accessed in the interrupt routine). There is a good chance therefore that the routine will not be called.
Try:
Code: |
#include <16F877.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,XT, PUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
int index=0;
byte buffer[2];
int1 received=false;
#int_RDA
void serial_isr()
{
buffer[index]=getch();
index = (index+1)&1;
received=true;
}
void main()
{
int i=0;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
'set_tris_b(0);
output_b(0);
'set_tris_d(0);
output_d(0);
You are not using fast_io, so do not need to set tris.
for(i=0;i<3;i++)
buffer[i]=0;
index=0;
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1) {
if (received) {
received=false;
output_b(buffer[0]);
output_d(buffer[1]);
}
}
}
|
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Mon Oct 17, 2005 7:05 am |
|
|
Ttelmah wrote: | Though it should work, the problem may be that the code as written is just missing the interrupts. You are accessing the array continuously in the external loop, which will imply that interrupts are disabled for this access (since the array is also accessed in the interrupt routine). There is a good chance therefore that the routine will not be called.
|
I don't think this will be an issue. If a character has arrived into the UART serialization buffer the interrupt flag will be set irresepective of when main processes the array the character received will be output to the port. The main loop is too short for characters to be missed given the baud rate and clock frequency. This also means that overrun would be unlikely.
I would look for a basic hardware problem. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Last edited by asmallri on Mon Oct 17, 2005 9:06 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Oct 17, 2005 9:03 am |
|
|
I´m also guess that you have a basic hardware problem.
Run this short code to be sure that your RS232 hardware was properly wired,
then try it with buffer + interupts.
Code: |
#include <16F877.h>
#fuses XT, NOWDT,PUT, NOPROTECT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
main()
{
char c;
printf(" test > ");
while(1)
{
c = getc();
putc(c);
}
}
|
Humberto |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Oct 17, 2005 10:41 am |
|
|
I would agree that a hardware problem is the most likely, but the problem I was thinking of, is one that I have seen on a couple of CCS releases. The compiler will disable interrupts for the entire array access, if it is used both inside and outside the loop. If the loop only contains array accesses, I have seen a couple of occasions, where the optimiser (especially with high optimisation settings), dealing with a loop like this, ends up putting the 'loop' jump inside the disable_interrupt section, resulting in the interrupts being left disabled. Even adding a single instruction (like a nop, or a delay), prevents it happening. It is a bug, but one that given the structure of the program, _might_ just be happening.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
hayy Guest
|
|
Posted: Tue Oct 18, 2005 3:58 am |
|
|
i ve already tried the
c=getch();
putch(c);
but i checked that com port works proper (loop back connect) but when i use getc function pic cannot receive data though it can send.
i am goning to try the operation with the receive flag . thanks |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Oct 18, 2005 6:54 am |
|
|
Quote: | but i checked that com port works proper (loop back connect) |
Are you saying that when you connected the Tx & Rx together that is recieve worked? If so, the problem is not with the PIC but rather the connections and/or the transmitting device. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|