|
|
View previous topic :: View next topic |
Author |
Message |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Dec 09, 2008 7:16 am |
|
|
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", 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
|
|
Posted: Tue Dec 09, 2008 9:18 am |
|
|
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", 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 . This is the problem. I was using this adress to update TRISB. .(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
|
|
Posted: Tue Dec 09, 2008 11:22 am |
|
|
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
|
|
Posted: Tue Dec 09, 2008 9:37 pm |
|
|
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 .... |
|
|
|
|
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
|