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

PIC24HJ128xxx and RS232 help !!!!!!!
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 7:16 am     Reply with quote

To supplement the suggestions by kartik. A cmd:
Code:
#use rs232(UART1,baud=9600)

is actually implementing UART2, selecting UART2 gives an error "no second UART", Surprised Unfortunately the interrupt code must use the templates provided by CCS, interrupts that have been forgotten for a device can't be used by other means.
smkul13



Joined: 04 Dec 2008
Posts: 8

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 9:18 am     Reply with quote

FvM wrote:
To supplement the suggestions by kartik. A cmd:
Code:
#use rs232(UART1,baud=9600)

is actually implementing UART2, selecting UART2 gives an error "no second UART", Surprised Unfortunately the interrupt code must use the templates provided by CCS, interrupts that have been forgotten for a device can't be used by other means.


I found out the problem & i m not using PCD functions any more now.

According to the datasheet the adress of TRISB is 0x02C8, but the PCD compiler's SFR window shows the adress of TRISB as 0x02C6 Evil or Very Mad Evil or Very Mad . This is the problem. I was using this adress to update TRISB. Evil or Very Mad .(both set_tris_b() & #byte TRISB 0x02c6 are wrong.)

I was mapping port b pins to UART1 and hence rs232() was using this wrong TRISB address to set pins of port b as i/p or o/p with no success. hence even soft UART is not working

FvM, when i used rs232(UART1, 9600), it was using UART2. This time i got suspicious and when i started to analyse SFR by SFR i found out that TRISB is wrongly addressed in PCD. But i dont know why UART2 is used instead of UART1 in above case.

And i belive such issues cannot be solved even though we go through manual n datasheets 1000 times. I religiously follwed PCD manual only to be left clueless.

But thx FvM for throwing light on this. Now i have to use #byte trisb 0x02c8.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 11:22 am     Reply with quote

I experienced usage of wrong addresses with some built-in functions, but I never used ICD-U40 with PIC24. It's better to perform some independant checking, at least in case of failure.

As karthik mentioned, you can code all UART accesses directly, by defining the SFRs through #bit, #byte and #word preprocessor commands.

The #int_rda and #int_rda2 commands are fortunately recognized by the compiler, which is necessary to assign the receiver interrupt functions to interrupt vectors, everything else can be achieved by user code.

As said, the #use rs232(UART1,..) cmd, also getch() and putch() are directed to UART2 and #int_rda2, a minor PCD bug. Accesses to UART1 (or UART3 and 4 with other PIC24 chips) have to be user coded.

It's useful to start with a SFR definition, including IO bits and bytes, as far as they are needed, e. g.

Code:
#bit TRISB12 = 0x2C8.12
#bit LATB12  = 0x2CC.12

#bit IOLOCK  = 0x742.6
#byte OSCCONL = 0x742

#byte RPINR18L = 0x6A4
#byte RPINR19L = 0x6A6
#byte RPOR2L = 0x6C4

The hardware setting equivalent to rcv=PIN_B5, xmit=PIN_B4 for UART2 is

Code:
OSCCONL = 0x46; // enabling the IOLOCK access
OSCCONL = 0x57;
IOLOCK = 0; // enable preipheral pin programming
RPINR19L = 5; // RX2 = RP5
RPOR2L = 5; // RP4 = TX2
OSCCONL = 0x46;
OSCCONL = 0x57;
IOLOCK = 1;
smkul13



Joined: 04 Dec 2008
Posts: 8

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 9:37 pm     Reply with quote

FvM wrote:
I experienced usage of wrong addresses with some built-in functions, but I never used ICD-U40 with PIC24. It's better to perform some independant checking, at least in case of failure.

As karthik mentioned, you can code all UART accesses directly, by defining the SFRs through #bit, #byte and #word preprocessor commands.

The #int_rda and #int_rda2 commands are fortunately recognized by the compiler, which is necessary to assign the receiver interrupt functions to interrupt vectors, everything else can be achieved by user code.

As said, the #use rs232(UART1,..) cmd, also getch() and putch() are directed to UART2 and #int_rda2, a minor PCD bug. Accesses to UART1 (or UART3 and 4 with other PIC24 chips) have to be user coded.

It's useful to start with a SFR definition, including IO bits and bytes, as far as they are needed, e. g.

Code:
#bit TRISB12 = 0x2C8.12
#bit LATB12  = 0x2CC.12

#bit IOLOCK  = 0x742.6
#byte OSCCONL = 0x742

#byte RPINR18L = 0x6A4
#byte RPINR19L = 0x6A6
#byte RPOR2L = 0x6C4

The hardware setting equivalent to rcv=PIN_B5, xmit=PIN_B4 for UART2 is

Code:
OSCCONL = 0x46; // enabling the IOLOCK access
OSCCONL = 0x57;
IOLOCK = 0; // enable preipheral pin programming
RPINR19L = 5; // RX2 = RP5
RPOR2L = 5; // RP4 = TX2
OSCCONL = 0x46;
OSCCONL = 0x57;
IOLOCK = 1;


Thanks FvM, as soon as I realised wrong address I am directly handling UART functions ....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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