1

I'm developing a project with dsPIC33EV256GM002 and I want to use its UART.

So I decided to use PIN18 as RX and PIN17 as TX so I programed PPS as follow:

// UART1 RX1 18 RP41 RPINR18 010 1001 (41)
// UART1 TX1 17 RP40 RPOR3.RP40R 000 0001 (1)
RPINR18bits.U1RXR=41;
RPOR3bits.RP40R = 1;

and I put PIN18 (RB 9) as input setting the bit9 of TRISB.

I used an external 8M XTAL and I set M,N1 and N2 parameter as follow:

// Configure Oscillator to operate the device at 80MHz/40MIPs
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 8M*40/(2*2)=80Mhz for 8M input clock
// To be safe, always load divisors before feedback


CLKDIVbits.PLLPOST = 0; // N1=2
CLKDIVbits.PLLPRE = 0; // N2=2
PLLFBD = 38; // M=(40-2), Fcyc = 40MHz for ECAN baud timer


// Disable Watch Dog Timer

RCONbits.SWDTEN = 0;

I want to configure the TX/RX port as 31250,N,8,1 (standard MIDI parameters)

// configure U1MODE
U1MODEbits.UARTEN = 0; // Bit15 TX, RX DISABLED, ENABLE at end of func
//U1MODEbits.notimplemented; // Bit14
U1MODEbits.USIDL = 0; // Bit13 Continue in Idle
U1MODEbits.IREN = 0; // Bit12 No IR translation
U1MODEbits.RTSMD = 0; // Bit11 Simplex Mode
//U1MODEbits.notimplemented; // Bit10
U1MODEbits.UEN = 0; // Bits8,9 TX,RX enabled, CTS,RTS not
U1MODEbits.WAKE = 0; // Bit7 No Wake up (since we don't sleep here)
U1MODEbits.LPBACK = 0; // Bit6 No Loop Back
U1MODEbits.ABAUD = 0; // Bit5 No Autobaud (would require sending '55')
U1MODEbits.URXINV = 0; // Bit4 IdleState = 1 (for dsPIC)
U1MODEbits.BRGH = 0; // Bit3 16 clocks per bit period
U1MODEbits.PDSEL = 0; // Bits1,2 8bit, No Parity
U1MODEbits.STSEL = 0; // Bit0 One Stop Bit



// U1BRG = (Fcy/(16*BaudRate))-1
// Fcy=40
// U1BRG = (40000000/(16*BaudRate))-1
// U1BRG = (40000000/(16*31250))-1 = 79

U1BRG = 79; // 40Mhz osc, 31250 Baud

// Load all values in for U1STA SFR
U1STAbits.UTXISEL1 = 0; //Bit15 Int when Char is transferred (1/2 config!)
U1STAbits.UTXINV = 0; //Bit14 N/A, IRDA config
U1STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15
//U1STAbits.notimplemented = 0; //Bit12
U1STAbits.UTXBRK = 0; //Bit11 Disabled
U1STAbits.UTXEN = 0; //Bit10 TX pins controlled by periph
U1STAbits.UTXBF = 0; //Bit9 *Read Only Bit*
U1STAbits.TRMT = 0; //Bit8 *Read Only bit*
U1STAbits.URXISEL = 0; //Bits6,7 Int. on character recieved
U1STAbits.ADDEN = 0; //Bit5 Address Detect Disabled
U1STAbits.RIDLE = 0; //Bit4 *Read Only Bit*
U1STAbits.PERR = 0; //Bit3 *Read Only Bit*
U1STAbits.FERR = 0; //Bit2 *Read Only Bit*
U1STAbits.OERR = 0; //Bit1 *Read Only Bit*
U1STAbits.URXDA = 0; //Bit0 *Read Only Bit*

IPC2bits.U1RXIP = 1; // Mid Range Interrupt Priority level, no urgent reason
IPC3bits.U1TXIP = 1; // Mid Range Interrupt Priority level, no urgent reason

IFS0bits.U1TXIF = 0; // Clear the Transmit Interrupt Flag
IEC0bits.U1TXIE = 1; // Enable Transmit Interrupts
IFS0bits.U1RXIF = 0; // Clear the Recieve Interrupt Flag
IEC0bits.U1RXIE = 1; // Enable Recieve Interrupts

U1MODEbits.UARTEN = 1; // And turn the peripheral on

for your reference this is the OSC configuration

     _FOSCSEL(FNOSC_PRIPLL);
 _FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_XT);
 // Startup directly into XT + PLL
 // OSC2 Pin Function: OSC2 is Clock Output
 // Primary Oscillator Mode: XT Crystal

 _FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software
 _FICD(ICS_PGD1); // PGD3 for external PK3/ICD3/RealIce, use PGD2 for PKOB

  _FDEVOPT( PWMLOCK_OFF );
  _FOSCSEL(FNOSC_PRIPLL);
  _FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_XT);
  // Startup directly into XT + PLL
  // OSC2 Pin Function: OSC2 is Clock Output
  // Primary Oscillator Mode: XT Crystal

Since I can't detect data from serial RX because I detect a framing error, I would know if the setting that I used are correct.

Have you similar experience ?

Ferrari
  • 75
  • 1
  • 11
  • Did you check if those pins had other functionality, like analog pin functionality that is default on? Analog pins are the most common reason for this kind of trouble. Does the formula that you use for brg match your brgh bit setting ? – Marco van de Voort Aug 11 '15 at 10:00

0 Answers0