|
|
View previous topic :: View next topic |
Author |
Message |
mizzard
Joined: 26 Apr 2009 Posts: 11
|
Problems using dspic33ep256mu806 hardware UARTs with PPS |
Posted: Thu Oct 18, 2012 10:16 am |
|
|
Hello everybody, I am going to explain my problem.
I am developing a prototype using dsPIC33EP256MU806, in wich I need to use the 4 hardware USARTs.
I use PCWHD compiler from CCS version 4.128
This PIC has the choice to select the I/O pin to every UART using the PPS. Then I try to configure like these options:
Every UARTs: 115200 bps, 8 bits no parity and stop bit.
PIC configured to work at 120 MHz from 4 MHz crystal (tested and it works).
UART1 -> xmit=PIN_D0, rcv=PIN_D8
UART2-> xmit=PIN_D1, rcv=PIN_D9
UART3 -> xmit=PIN_D2, rcv=PIN_D10
UART4 -> xmit=PIN_B7, rcv=PIN_B6
I attach my code:
<main.h>
Code: | #include <33EP256MU806.h>
//#device adc=10
#FUSES NODEBUG //No Debug mode for ICD
#FUSES PUT128 //Power On Reset Timer value 128ms
#FUSES NOWDT //No Watch Dog Timer
#FUSES PR_PLL
#FUSES HS
#FUSES ICSP1
#FUSES OSCIO
#FUSES CKSFSM
// OSCILLATOR CONFIGURATION
#WORD CLKDIV = 0x0744 //PLLPOST(6,7) - PLLPRE(0,1,2,3,4)
#BIT PLLPOST_0 = CLKDIV.6
#BIT PLLPOST_1 = CLKDIV.7
#BIT PLLPRE_0 = CLKDIV.0
#BIT PLLPRE_1 = CLKDIV.1
#BIT PLLPRE_2 = CLKDIV.2
#BIT PLLPRE_3 = CLKDIV.3
#BIT PLLPRE_4 = CLKDIV.4
#WORD PLLFBD = 0x0746 //PLLDIV(0,1,2,3,4,5,6,7,8)
#BIT PLLDIV_0 = PLLFBD.0
#BIT PLLDIV_1 = PLLFBD.1
#BIT PLLDIV_2 = PLLFBD.2
#BIT PLLDIV_3 = PLLFBD.3
#BIT PLLDIV_4 = PLLFBD.4
#BIT PLLDIV_5 = PLLFBD.5
#BIT PLLDIV_6 = PLLFBD.6
#BIT PLLDIV_7 = PLLFBD.7
#BIT PLLDIV_8 = PLLFBD.8
#WORD OSCCON = 0x0742 // OSWEN(0) - NOSC(8,9,10)
#BIT OSWEN = OSCCON.0
#BIT NOSC_0 = OSCCON.8
#BIT NOSC_1 = OSCCON.9
#BIT NOSC_2 = OSCCON.10
#use delay(clock=120000000)
// I/O CONFIGURATION
#BIT IOLOCK = OSCCON.6
// INPUTS
#WORD RPINR18 = 0x06C4 // U1RXR(0,1,2,3,4,5,6)
#BIT U1RXR_0 = RPINR18.0
#BIT U1RXR_1 = RPINR18.1
#BIT U1RXR_2 = RPINR18.2
#BIT U1RXR_3 = RPINR18.3
#BIT U1RXR_4 = RPINR18.4
#BIT U1RXR_5 = RPINR18.5
#BIT U1RXR_6 = RPINR18.6
#WORD RPINR19 = 0x06C6 // U2RXR(0,1,2,3,4,5,6)
#BIT U2RXR_0 = RPINR19.0
#BIT U2RXR_1 = RPINR19.1
#BIT U2RXR_2 = RPINR19.2
#BIT U2RXR_3 = RPINR19.3
#BIT U2RXR_4 = RPINR19.4
#BIT U2RXR_5 = RPINR19.5
#BIT U2RXR_6 = RPINR19.6
#WORD RPINR27 = 0x06D6 // U3RXR(0,1,2,3,4,5,6)
#BIT U3RXR_0 = RPINR27.0
#BIT U3RXR_1 = RPINR27.1
#BIT U3RXR_2 = RPINR27.2
#BIT U3RXR_3 = RPINR27.3
#BIT U3RXR_4 = RPINR27.4
#BIT U3RXR_5 = RPINR27.5
#BIT U3RXR_6 = RPINR27.6
#WORD RPINR28 = 0x06D8 // U4RXR(0,1,2,3,4,5,6)
#BIT U4RXR_0 = RPINR28.0
#BIT U4RXR_1 = RPINR28.1
#BIT U4RXR_2 = RPINR28.2
#BIT U4RXR_3 = RPINR28.3
#BIT U4RXR_4 = RPINR28.4
#BIT U4RXR_5 = RPINR28.5
#BIT U4RXR_6 = RPINR28.6
// OUTPUTS
#WORD RPOR0 = 0x0680 // RP64R(0,1,2,3,4,5) - RP65R(8,9,10,11,12,13)
#BIT RP64R_0 = RPOR0.0
#BIT RP64R_1 = RPOR0.1
#BIT RP64R_2 = RPOR0.2
#BIT RP64R_3 = RPOR0.3
#BIT RP64R_4 = RPOR0.4
#BIT RP64R_5 = RPOR0.5
#BIT RP65R_0 = RPOR0.8
#BIT RP65R_1 = RPOR0.9
#BIT RP65R_2 = RPOR0.10
#BIT RP65R_3 = RPOR0.11
#BIT RP65R_4 = RPOR0.12
#BIT RP65R_5 = RPOR0.13
#WORD RPOR1 = 0x0682 // RP66R(0,1,2,3,4,5) - RP67R(8,9,10,11,12,13)
#BIT RP66R_0 = RPOR1.0
#BIT RP66R_1 = RPOR1.1
#BIT RP66R_2 = RPOR1.2
#BIT RP66R_3 = RPOR1.3
#BIT RP66R_4 = RPOR1.4
#BIT RP66R_5 = RPOR1.5
#BIT RP67R_0 = RPOR1.8
#BIT RP67R_1 = RPOR1.9
#BIT RP67R_2 = RPOR1.10
#BIT RP67R_3 = RPOR1.11
#BIT RP67R_4 = RPOR1.12
#BIT RP67R_5 = RPOR1.13
#WORD TRISD = 0x0E30
#BIT TRISD_8 = TRISD.8
#BIT TRISD_0 = TRISD.0
// DESIRED HARDWARE RS232
#use rs232( stream = U1, xmit=PIN_D0, rcv=PIN_D8, baud=115200, parity=N, bits=8,errors)
//#use rs232(stream = U2, xmit=PIN_D1, rcv=PIN_D9, baud=115200, parity=N, bits=8,errors)
//#use rs232(stream = U3, xmit=PIN_D2, rcv=PIN_D10, baud=115200, parity=N, bits=8,errors)
//#use rs232(stream = U4, xmit=PIN_D3, rcv=PIN_D11, baud=115200, parity=N, bits=8,errors)
// SOFTWARE RS232
#use rs232(stream = DEBUG, xmit=PIN_B7, rcv=PIN_B6, baud=115200, parity=N, bits=8)
|
<main.c>
Code: | #include <main.h>
#include <math.h>
#include <string.h>
#INT_RDA
void uart1_interrupt(void){
fprintf(DEBUG,"A\r\n");
clear_interrupt(INT_RDA);
}
#INT_RDA2
void uart2_Interrupt(void){
fprintf(DEBUG,"B\r\n");
clear_interrupt(INT_RDA2);
}
#INT_RDA3
void uart3_Interrupt(void){
fprintf(DEBUG,"C\r\n");
clear_interrupt(INT_RDA3);
}
#INT_RDA4
void uart4_Interrupt(void){
fprintf(DEBUG,"D\r\n");
clear_interrupt(INT_RDA4);
}
void main(){
// OSCILLATOR CONFIGURATION, USING 4MHz XTAL
// _ _ _ -
// | M | | (PLLDIV+2) |
// Fosc = Fin x | ------ | = Fin x | ---------------------- |
// (3-5.5MHz) | N1xN2 | | (PLLPRE+2)x2(PLLPOST+1)|
// - - - -
// XT/HS with PLL -> Fin = 4 MHz
OSWEN = 1;
NOSC_0 = 1;
NOSC_1 = 1;
NOSC_2 = 0;
// PLLPRE=0 Luego N1=2
PLLPRE_0 = 0;
PLLPRE_1 = 0;
PLLPRE_2 = 0;
PLLPRE_3 = 0;
PLLPRE_4 = 0;
// PLLPOST=0 Luego N2=2
PLLPOST_0 = 0;
PLLPOST_1 = 0;
// PLLDIV=118 Luego M=120
PLLDIV_0 = 0;
PLLDIV_1 = 1;
PLLDIV_2 = 1;
PLLDIV_3 = 0;
PLLDIV_4 = 1;
PLLDIV_5 = 1;
PLLDIV_6 = 1;
PLLDIV_7 = 0;
PLLDIV_8 = 0;
// Wait for oscillator
delay_ms(500);
// unlock security
IOLOCK = 0;
// Connections
// UART1 RX1 -> PIN RPI72 (PIN_D8)
U1RXR_0 = 0;
U1RXR_1 = 0;
U1RXR_2 = 0;
U1RXR_3 = 1;
U1RXR_4 = 0;
U1RXR_5 = 0;
U1RXR_6 = 1;
TRISD_8 = 1;
// UART1 TX1 -> PIN RP64 (PIN_D0)
RP64R_0 = 1;
RP64R_1 = 0;
RP64R_2 = 0;
RP64R_3 = 0;
RP64R_4 = 0;
RP64R_5 = 0;
TRISD_8 = 0;
// Lock security pin
IOLOCK = 1;
enable_interrupts(INT_RDA);
delay_ms(3000);
fprintf(DEBUG,"Arranco\r\n");
while(true){
//<----------- DEBUG
fputc(0xAA,U1);
fputc(0x01, U1);
fputc(0x02, U1);
fputc(0x0d, U1);
fputc(0x0a,U1);
delay_ms(1000);
// fprintf(DEBUG,"NUM UARTS HW: %i\r\n",getenv("UART"));
}
}
|
As you can see, I have simplified the code ( I prepare 4 UARTs but only configure one of them). I have checked that when I send the message described inside the while another PIC answer it (runs OK), so for this reason it could have an interrupt on INT_RDA (only to show, no message analysis).
I have only do that for 1 UART because I think that is the same for the others.
The problem that I have is I never can see the INT_RDA interrupt and I don’t know what to do.
If anyone could help me I will be very pleased.
I hope your answers, thanks a lot. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Oct 19, 2012 6:26 am |
|
|
Printing inside an interrupt handler is not going to work. Instead set flags in the interrupt handler and then in the mainline check to state of the flags, if set then clear the appropriate flag and output the desired message. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Fri Oct 19, 2012 6:38 am |
|
|
You are not using the hardware UART. On most of the DSPIC's you have to use #PIN SELECT to tell the compiler to connect the UARTx to the I/O pins, then use the UARTx form in the #USE RS232.
So:
Code: |
#PIN SELECT U1TX=PIN_D0
#PIN_SELECT U1RX=PIN_D1
#USE RS232(UART1, ERRORS, STREAM=U1, BAUD=115200)
|
If you just tell the compiler to use RS232 on pins that _can_ be the UART pins, but have not been selected as such, it generates a software UART, so no interrupt....
Best Wishes |
|
|
mizzard
Joined: 26 Apr 2009 Posts: 11
|
|
Posted: Mon Nov 05, 2012 5:02 am |
|
|
Ttelmah wrote: | You are not using the hardware UART. On most of the DSPIC's you have to use #PIN SELECT to tell the compiler to connect the UARTx to the I/O pins, then use the UARTx form in the #USE RS232.
So:
Code: |
#PIN SELECT U1TX=PIN_D0
#PIN_SELECT U1RX=PIN_D1
#USE RS232(UART1, ERRORS, STREAM=U1, BAUD=115200)
|
If you just tell the compiler to use RS232 on pins that _can_ be the UART pins, but have not been selected as such, it generates a software UART, so no interrupt....
Best Wishes |
Thanx Ttelmah, problem solved |
|
|
|
|
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
|