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

receive interrupt on pic24fj256gb110

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



Joined: 23 Feb 2009
Posts: 10

View user's profile Send private message

receive interrupt on pic24fj256gb110
PostPosted: Tue Feb 24, 2009 2:15 am     Reply with quote

I am trying to get data from user on pic24fj256gb110, after success in printing out, I now need to receive charecter, I have tried many things with no luck,
please help

10q,

nira
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Feb 24, 2009 4:42 am     Reply with quote

The built-in stdio RS232 functions are directed to UART2, other UARTs can be accessed through respective SFRs directly. Also the peripheral pins selects must be set for the respective UART IOs.

Some aspects of PIC24 UART usage have been previously discussed, see e.g.: http://www.ccsinfo.com/forum/viewtopic.php?t=36976&

Can you show your existing INT_RDA code?
nirayo



Joined: 23 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Wed Feb 25, 2009 2:31 am     Reply with quote

FvM
the example works fine, this is the basic way to see that everything works, thank you, I now know that the hardware is O.K.
I will try to write with interrupt again, (not very optimistic...)
I'll let you know hoe it goes
thanks again
Nirayo
nirayo



Joined: 23 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Wed Feb 25, 2009 2:59 am     Reply with quote

FvM wrote:
The built-in stdio RS232 functions are directed to UART2, other UARTs can be accessed through respective SFRs directly. Also the peripheral pins selects must be set for the respective UART IOs.

Some aspects of PIC24 UART usage have been previously discussed, see e.g.: http://www.ccsinfo.com/forum/viewtopic.php?t=36976&

Can you show your existing INT_RDA code?



here is my code:

char msg_reply[5];
#define BUFFER_SIZE 5
BYTE next_in = 0;
BYTE next_out = 0;
char done;

//========================================//
#int_rda
void get_msg_uart2()
{
int t;
msg_reply[next_in]=getc();
if(msg_reply[next_in] == 0x0d)
{
done = 1;
}
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==next_out)
{
next_in=t; // Buffer full !!
}
}

it is copied from the pic compiler examples, with a few revision of my own, it's not working, I don't see that the program enters the interrupt

help!!!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Feb 25, 2009 3:27 am     Reply with quote

I just realized, I forgot to mention, UART2 IRQ uses #INT_RDA2. I guess, that's why your code doesn't work. Also enable_interrupts(INT_RDA2); has to executed.
nirayo



Joined: 23 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Thu Feb 26, 2009 2:52 am     Reply with quote

been there, done that, didn't work
I have read something in the datasheet about interrupt vector for this chip
how does this work exactly? is there some initialization I need to perform ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Feb 26, 2009 3:15 am     Reply with quote

See below my relevant code parts. Interrupt vector is setup automaticly by using the #INT_RDA2 directive.

Code:
#use rs232(UART1,baud=38400,parity=N,bits=8)

#int_RDA2
void  RDA2_isr(void)
{
   BYTE        bTemp;
   BYTE        c;
   c=getc();

   SRecBuf[SRecNextIn]=c;
   bTemp = SRecNextIn;
   // REC_BUF_SIZE must be power of two to use & mask
   SRecNextIn = (SRecNextIn + 1) & (REC_BUF_SIZE-1);
   if(SRecNextIn == SRecNextOut)
   {
      SRecNextIn = bTemp;
   }
}

void main(void)
{
// Setup peripheral pin selects, should work by PCS built-in functions as well   
   OSCCONL = 0x46;
   OSCCONL = 0x57;
   IOLOCK = 0;

   RPINR19L = 27; // UART2 Receive = RP27
   RPOR14L = 5;   // UART2 Transmit

   OSCCONL = 0x46;
   OSCCONL = 0x57;
   IOLOCK = 1;
// ...
   enable_interrupts(INT_RDA2);
   enable_interrupts(INTR_GLOBAL);
// ...
}
nirayo



Joined: 23 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Thu Feb 26, 2009 4:03 am     Reply with quote

hello FvM
thank you so much for your help,
I'm sorry, but it seems you are going to have to feed me on this one.
I have looked through the datasheet, and still don't understand,
how do I define this:
OSCCONL
IOLOCK
RPINR19L
RPOR14L

thank you
nirayo

p.s. I am working on pcd 24 bit with pic c compiler ver.4.085


Last edited by nirayo on Thu Feb 26, 2009 4:43 am; edited 1 time in total
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Feb 26, 2009 4:41 am     Reply with quote

The said code sequence is for unlocking the peripheral pin select registers, only necessary if you intend to set them manually. I generally do this in my code, cause I experienced the PCD built-in functions with peripheral pin selects working incorrectly, at least with some pin functions and some PCD revisions back.

If your UART is basically working in non-interrupt operation, your method of setting the pins would have proved correct and you can ignore this part of my code. Otherwise, you have to use your application settings here rather than mine.

I you still don't succeed, I suggest to assemble a minimal UART I/O application that is supposed to work as is (e.g. including all initializations) and post it here.

B.T.W., does a non-interrupt UART handling work:

Code:
void main(void)
{
printf("Here I am\r\n");
while (1)
// echo all
  putc(getc());
}
nirayo



Joined: 23 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Thu Feb 26, 2009 4:56 am     Reply with quote

the basic example works just great, realy echos what i write in the terminal,
without interrupts. But I realy need the interrupts, since I am not supposed to know when the input is coming
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Feb 27, 2009 11:20 am     Reply with quote

Yes I see. As I said, it's generally working (for all four UARTs). Post a complete example.
nirayo



Joined: 23 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Thu Mar 12, 2009 4:03 am     Reply with quote

thank you FvM,
I have succeeded l
got some help from another friend
turns out I needed to map all the registers manually
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