• AVR Freaks

Hot!dspic

Author
S12345S
S12345S
  • Total Posts : 9
  • Reward points : 0
  • Status: offline
2019/08/13 03:47:33 (permalink)
0

dspic

hai
I using dsPIC33EP512MU810 Microcontroller . And need help how to read a string from terminal.  
 
 
 
char ReceivedChar;
 
void putchar_u1(unsigned char c)
{
    while ( U3STAbits.UTXBF); // wait while Tx buffer full
     U3TXREG = c;
}
 
void __attribute__ ( (interrupt, no_auto_psv) ) _U3RXInterrupt( void )
{
      if(U3STAbits.URXDA == 1)
        ReceivedChar = U3RXREG;
       putchar_u1(ReceivedChar);
       IFS5bits.U3RXIF = 0;
}
 
 
void __attribute__ ( (interrupt, no_auto_psv) ) _U3TXInterrupt( void )
{
       IFS5bits.U3TXIF = 0;
}
 
 
void InitClock( void )
{
        PLLFBD = 58; // M = 60
       CLKDIVbits.PLLPOST = 0; // N1 = 2
        CLKDIVbits.PLLPRE = 0; // N2 = 2
      OSCTUN = 0;
      RCONbits.SWDTEN = 0;
// Clock switch to incorporate PLL
     __builtin_write_OSCCONH( 0x03 ); // Initiate Clock Switch to
// External oscillator with PLL (NOSC=0b011)
     __builtin_write_OSCCONL( OSCCON || 0x01 ); // Start clock switching
             while( OSCCONbits.COSC != 0b011 );
// Wait for Clock switch to occur
            while( OSCCONbits.LOCK != 1 )
           { };
}
 
void InitUART3( void )
{


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

U3BRG = 389; // 60Mhz osc, 9600 Baud
U3STAbits.UTXISEL0 = 0; // Interrupt after one TX character is transmitted
U3STAbits.UTXISEL1 = 0;
// Load all values in for U1STA SFR
// U3STAbits.UTXISEL1 = 0; //Bit15 Int when Char is transferred (1/2 config!)
// U3STAbits.UTXINV = 0; //Bit14 N/A, IRDA config
// U3STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15
//U1STAbits.notimplemented = 0;//Bit12
U3STAbits.UTXBRK = 0; //Bit11 Disabled
U3STAbits.UTXEN = 0; //Bit10 TX pins controlled by periph
U3STAbits.UTXBF = 0; //Bit9 *Read Only Bit*
U3STAbits.TRMT = 0; //Bit8 *Read Only bit*
U3STAbits.URXISEL = 0; //Bits6,7 Int. on character recieved
U3STAbits.ADDEN = 0; //Bit5 Address Detect Disabled
U3STAbits.RIDLE = 0; //Bit4 *Read Only Bit*
U3STAbits.PERR = 0; //Bit3 *Read Only Bit*
U3STAbits.FERR = 0; //Bit2 *Read Only Bit*
U3STAbits.OERR = 0; //Bit1 *Read Only Bit*
U3STAbits.URXDA = 1; //Bit0 *Read Only Bit*
IPC20 = 0x4400; // Mid Range Interrupt Priority level, no urgent reason
IEC5bits.U3TXIE = 1; // Enable Transmit Interrupts
IFS5bits.U3RXIF = 0; // Clear the Recieve Interrupt Flag
IEC5bits.U3RXIE = 1; // Enable Recieve Interrupts
RPOR5 = 0;
RPOR5bits.RP84R = 27; //RE4/RP84 as U3TX
RPINR27bits.U3RXR = 83; //RE3/RPI83
U3MODEbits.UARTEN = 1; // And turn the peripheral on
U3STAbits.UTXEN = 1;
IFS5bits.U3TXIF = 0;
}
 
int main( void )
{
   InitClock(); 
   InitUART3();
   while(1)
  {
   }
}
post edited by S12345S - 2019/08/13 09:55:52
#1

5 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3175
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: uart3 receiving string problem 2019/08/13 04:29:04 (permalink)
    0
    What - precisely - is your problem ?
    And - BTW: who are you ??

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    S12345S
    S12345S
    • Total Posts : 9
    • Reward points : 0
    • Status: offline
    Re: uart3 rX PROBLEM 2019/08/13 06:07:26 (permalink)
    1 (1)
    HOW TO RECEIVE AND TRANSMIT A STRING BY USING UART for dspic33ep512mu810 microcontroller.
    post edited by S12345S - 2019/08/13 09:50:43
    #3
    du00000001
    Just Some Member
    • Total Posts : 3175
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: uart3 receiving string problem 2019/08/13 09:15:19 (permalink)
    4 (1)
    Seems to become really difficult ...
     
    • What's your education and experience level?
    • Is your current receive/retransmit function working ?
      (If not: are you able to receive anything at all? Maybe in poll mode?)
     

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    NorthGuy
    Super Member
    • Total Posts : 5754
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: uart3 receiving string problem 2019/08/13 10:56:57 (permalink)
    5 (2)
    Start from small things and add in little increments.
     
    First, blink LED.
     
    Then configure the transmitter only. See if it transmits anything by looking at the TX trace with scope or LA.
     
    Make sure the transmit speed (baud rate) is Ok.
     
    Then configure the receiver and feed the signal from transmitter to the receiver. Make sure it receives.
     
    Etc.
    #5
    AKJ
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2019/05/27 06:55:52
    • Location: 0
    • Status: offline
    Re: uart3 receiving string problem 2019/08/14 03:19:29 (permalink)
    0
    I learnt after trying so hard, that the best way to show content to the user using PICs, is to add a breakpoint for debugging.
    So do something like 

    if (someVariable == true)
    {
       someOtherVariable = true;
    }

    and add a breakPoint after this code. Look for the variable in the debugger and see their current values.
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5