dspic33EP UART pin
Répondre à la discussion
Affichage des résultats 1 à 21 sur 21

dspic33EP UART pin



  1. #1
    invite21ace5e2

    dspic33EP UART pin


    ------

    Bonjour à tous,

    J'utilise un dspic33EP512GM710 avec un carte Explorer 16. J'aimerais utiliser le module UART avec un communication RS232 pour effectuer une Interface sur PC. Le problème c'est que sur la datasheet du micro, je ne vois aucune pin UxTX ou UxRX.

    Je n'arrive pas à faire la communication. Comment retrouver les pins qui relie le port RS232 de la carte Explorer16 à mon micro ?

    Si quelqu'un à déjà eu ce souci ...

    Merci d'avance
    Marc

    -----

  2. #2
    antek

    Re : dspic33EP UART pin

    Citation Envoyé par marc64ab Voir le message
    J'utilise un dspic33EP512GM710 avec un carte Explorer 16. J'aimerais utiliser le module UART avec un communication RS232 pour effectuer une Interface sur PC. Le problème c'est que sur la datasheet du micro, je ne vois aucune pin UxTX ou UxRX.
    Je n'arrive pas à faire la communication. Comment retrouver les pins qui relie le port RS232 de la carte Explorer16 à mon micro ?
    Donner un lien vers la doc évite de chercher . . .
    Sur le schéma de la carte explorer16 !
    Chez moi c'est une prise 8 pin nommée P1.

  3. #3
    invite21ace5e2

    Re : dspic33EP UART pin

    désolé,

    doc dspic33EP512GM710 : http://ww1.microchip.com/downloads/e.../70000689d.pdf
    page 7 pin diagrams

    doc Carte explorer 16 : http://ww1.microchip.com/downloads/e...Doc/51589a.pdf

    Ce que je comprend pas c'est que dans les exemples ils utilisent la pin UxTX et UxRX, mais sur mon pic elles ne sont pas présentes.

    Merci
    Marc

  4. #4
    antek

    Re : dspic33EP UART pin

    Citation Envoyé par marc64ab Voir le message
    doc dspic33EP512GM710 : http://ww1.microchip.com/downloads/e.../70000689d.pdf
    page 7 pin diagrams
    doc Carte explorer 16 : http://ww1.microchip.com/downloads/e...Doc/51589a.pdf
    Ce que je comprend pas c'est que dans les exemples ils utilisent la pin UxTX et UxRX, mais sur mon pic elles ne sont pas présentes.
    Ben moi je les vois très bien !
    Il y a 4 UART. La sortie RS232 est connectée au max232, lui-même connecté à UART2.
    Quand tu lis UxTX dans un exemple, ça veux dire que c'est à toi de déterminer le UART utilisé.
    UxRX et UxTX -> à toi de remplacer "x" par 1, 2, 3 ou 4.

  5. A voir en vidéo sur Futura
  6. #5
    invite21ace5e2

    Re : dspic33EP UART pin

    Je sais bien que les x doivent être remplacer j'ai quelques notions en programmation pic.

    Cependant, ce que je ne comprend c'est que j'arrive pas à voir ce que j'envoie sur le pc, de simples chiffre ou lettres, sur realterm. J'ai l'impression que la communication ne se fait pas.
    J'ai remarqué que sur différent pic les pins ne correspondent pas. Par exemple, prenons un dspic33F256GP710A sur la doc suivante page 17 : http://ww1.microchip.com/downloads/e...Doc/70593B.pdf
    les pins pour l'UART 2 sont 49 et 50 avec UR2X et U2TX. Si je prend mon pic, les pins 49 et 50 ne fait référence à aucun UART, n'est ce pas ?

    alors ma question est : comment fait la com RS232 pour chercher la bonne pin ?

    J’espère être assez claire.
    Merci d'avance pour vos info
    Marc

  7. #6
    antek

    Re : dspic33EP UART pin

    Citation Envoyé par marc64ab Voir le message
    J'ai remarqué que sur différent pic les pins ne correspondent pas. Par exemple, prenons un dspic33F256GP710A sur la doc suivante page 17 : http://ww1.microchip.com/downloads/e...Doc/70593B.pdf
    les pins pour l'UART 2 sont 49 et 50 avec UR2X et U2TX. Si je prend mon pic, les pins 49 et 50 ne fait référence à aucun UART, n'est ce pas ?
    alors ma question est : comment fait la com RS232 pour chercher la bonne pin ?
    C'est pas la distribution des pin sur le PIC qui importe, c'est le cablage des PIM.
    Tu utilises quel PIM ?

  8. #7
    invite21ace5e2

    Re : dspic33EP UART pin

    C'est quoi une PIM ?

  9. #8
    antek

    Re : dspic33EP UART pin

    Citation Envoyé par marc64ab Voir le message
    C'est quoi une PIM ?
    Plug In Module
    J'ai peur de n'avoir pas saisi quelque chose.
    Comment installes-tu les PIC sur la carte explorer16 ?
    Les PIC sont montés sur des modules que tu enfiches sur la carte ?

  10. #9
    invite21ace5e2

    Re : dspic33EP UART pin

    oui le pic est sur un module enfichable que j'insère directement sur la carte Explorer 16. Du coup les pins sont déjà reliées. C'est pour ça que je pense que le RS232 n'est pas forcèment relié à l'UART2 sachant que je sais que sur un dspic33F256GP710A, il est relié sur les pins 49 et 50.

    Le plug in module est surement le module UART. J'arrive pas à saisir ce que c'est exactement.

  11. #10
    antek

    Re : dspic33EP UART pin

    Citation Envoyé par marc64ab Voir le message
    oui le pic est sur un module enfichable que j'insère directement sur la carte Explorer 16. Du coup les pins sont déjà reliées. C'est pour ça que je pense que le RS232 n'est pas forcèment relié à l'UART2 sachant que je sais que sur un dspic33F256GP710A, il est relié sur les pins 49 et 50.
    Le plug in module est surement le module UART. J'arrive pas à saisir ce que c'est exactement.
    Donne le lien vers le module que tu utilises !
    Ou la référence si t'en n'as pas.

  12. #11
    invite21ace5e2


  13. #12
    invite21ace5e2

    Re : dspic33EP UART pin

    Voici mon programme que j'essaie de faire fonctionne sur realterm pour voir si il envoie bien ce que je veux sur le pc

    Code:
    #include <p33EP512GM710.h>
    #include <math.h>
    #include<stdbool.h>
    
    #define FP 70000000
    #define BAUDRATE 115200
    #define BRGVAL ((FP/BAUDRATE)/16)-1
    
    
    //--- Configuration ---//
    _FOSCSEL( FNOSC_PRI );                              // Select Primary Oscillator (Posc) at POR (Power-on Reset)
    _FOSC( POSCMD_XT & OSCIOFNC_OFF & FCKSM_CSECMD );   // Configure Posc in HS mode, Enable clock switching
    _FWDT( WDTPOST_PS32768 & FWDTEN_OFF );
    _FICD( JTAGEN_OFF );
    
    //--- prototype de fonction ---//
    
    void Init_Osci(void);
    void Init_Timer2(void);
    void Init_Port(void);
    void wait(void);
    void InitUART2(void);
    
    #define TRUE	1
    #define FALSE	0
    
    bool Config_OK=0, Start=0;
    int z=1, i=1, j=0, count_1s=0;
    char bufferTx[10];
    char bufferRx[10];
    int compteur=10;
    char buffer[10];
    char temp_buffer;
    
    unsigned char S3Flag, S4Flag, S5Flag, S6Flag;
    
    int main(void)
    {
    
        RCONbits.SWDTEN=0;          // Disable Watch Dog Timer
    
        Init_Port();
        Init_Osci();                // Oscilator initialisation
        Init_Timer2();              // Timer2 initialisation
        InitUART2();                // Initialize UART2 for 115200,8,N,1 TX/RX
    
    
    
                                bufferTx[0]='$';
                                bufferTx[1]='1';
                                bufferTx[2]='2';
                                bufferTx[3]='3';
                                bufferTx[4]='4';
                                bufferTx[5]='5';
                                bufferTx[6]='6';
                                bufferTx[7]='7';
                                bufferTx[8]='8';
                                bufferTx[9]='9';
    
    
    
    
                        if (IEC1bits.U2TXIE == 0)
                            {
                                IFS1bits.U2TXIF = 0;
                                IEC1bits.U2TXIE = 1;
                                U2TXREG = buffer[0];
    
                            }
    
    	while(1)
            {
                
            }
    }
    
    /*---------------------------------------------------------------------
      Function Name: newparametre
      Description:   nouveau parametre PWM
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void wait (void)
    {
        long h=900000;
        while(h)
        {
            h--;
        }
    }
    
    
    /*---------------------------------------------------------------------
      Function Name: Init_Osci
      Description:   Initialize oscillator
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void Init_Osci( void )    // Fonction pour initialiser l'oscillateur
    
    {
         // Configure Oscillator to operate the device at 70Mhz
        // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
        // Fosc= 8M*245/(2*7)=140Mhz for 8M input clock
    
        // Configure PLL prescaler, PLL postscaler, PLL divisor
        CLKDIV = 0x05; 			// N2 = 7 N1=2
        PLLFBD = 0xF3;			// M = 245
    
        //  Clock switching to incorporate PLL (NOSC=0b011)
        __builtin_write_OSCCONH(0x03); 		// Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011)										// configuration du registre NOSC (OSCCON) -->
        __builtin_write_OSCCONL(0x01);		// Start clock switching
    
        // Wait for Clock switch to occur
        while(OSCCONbits.COSC != 0b011);
    
        // Wait for PLL to lock
        while(OSCCONbits.LOCK != 1);
    }
    
    
    /*---------------------------------------------------------------------
      Function Name: Init_Port
      Description:   Initialize I/O
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void Init_Port( void )      // Fonction pour initialiser les I/O
    
    {
        // S3 (portD Pin 6, chosen as trigger for sending 'M' to UART)
        // S6 (portC Pin 9, chosen as trigger for sending 'C' to UART)
        // S5 (portF Pin 7, chosen as trigger for sending 'H' to UART)
        // S4 (portD Pin 13, chosen as trigger for sending 'P' to UART)
        ANSELA = 0;
        ANSELC = 0;
        ANSELD = 0;
        ANSELF = 0;
    
        // we need to config the pin as DIGITAL
        TRISD = 0x2040;         // D6,D13 inputs
        TRISFbits.TRISF7 = 1;   // f7 is input
        TRISCbits.TRISC9 = 1;   //C9 is input
        TRISBbits.TRISB4 = 0;   //B4 as output
        TRISAbits.TRISA8 = 1;   //A8 as input
        S3Flag = S4Flag = S5Flag = S6Flag = 0;	// Some Debounce Flags
    }
    
    
    /*---------------------------------------------------------------------
      Function Name: Init_Timer2
      Description:   Initialize Timer2 10kHz ---> 100us
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void Init_Timer2( void )    // Initialize Timer2
    
    {
        T2CONbits.TON = 0;      // Disable Timer
        T2CONbits.T32 = 0;      // Timer 16 bits
        T2CONbits.TCS = 0;      // Select internal instruction cycle clock (Fosc/2)
        T2CONbits.TGATE = 0;    // Disable Gated Timer mode
        T2CONbits.TCKPS = 0;    // Select 1:1 Prescaler (70MHz--->14285ps)
    
    
        IFS0bits.T2IF = 0;      // Reset Timer2 interrupt flag
        IPC1bits.T2IP = 2;      // Timer2 Interrupt priority level=4
        IEC0bits.T2IE = 1;      // Enable Timer2 interrupt
    
        TMR2= 0;                // Clear timer register
        PR2 = 6960;             // Load the period value (100us/14285ps=7000)   6960 pour l'ajustement
    
        T2CONbits.TON = 1;      // Enable Timer2 and start the counter
    }
    
    
    
    /*---------------------------------------------------------------------
      Function Name: InitUART1
      Description:   Initialisation de l'UART
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void InitUART2()
    {
          // This is an EXAMPLE, so brutal typing goes into explaining all bit sets
    
    	// The HPC16 board has a DB9 connector wired to UART2, so we will
    	// be configuring this port only
    
    	// configure U2MODE
    	U2MODEbits.UARTEN = 0;	// Bit15 TX, RX DISABLED, ENABLE at end of func
    	//U2MODEbits.notimplemented;	// Bit14
    	U2MODEbits.USIDL = 0;	// Bit13 Continue in Idle
    	U2MODEbits.IREN = 0;	// Bit12 No IR translation
    	U2MODEbits.RTSMD = 0;	// Bit11 Simplex Mode
    	//U2MODEbits.notimplemented;	// Bit10
    	U2MODEbits.UEN = 0;		// Bits8,9 TX,RX enabled, CTS,RTS not
    	U2MODEbits.WAKE = 0;	// Bit7 No Wake up (since we don't sleep here)
    	U2MODEbits.LPBACK = 0;	// Bit6 No Loop Back
    	U2MODEbits.ABAUD = 0;	// Bit5 No Autobaud (would require sending '55')
    	U2MODEbits.URXINV = 0;	// Bit4 IdleState = 1  (for dsPIC)
    	U2MODEbits.BRGH = 0;	// Bit3 16 clocks per bit period
    	U2MODEbits.PDSEL = 0;	// Bits1,2 8bit, No Parity
    	U2MODEbits.STSEL = 0;	// Bit0 One Stop Bit
    
    	// Load a value into Baud Rate Generator.  Example is for 9600.
    	// See section 19.3.1 of datasheet.
    	//  U2BRG = (Fcy/(16*BaudRate))-1
    	//  U2BRG = (37M/(16*9600))-1
    	//  U2BRG = 240
    	U2BRG = BRGVAL;	// 40Mhz osc, 9600 Baud,
    
    	// Load all values in for U1STA SFR
    	U2STAbits.UTXISEL1 = 0;	//Bit15 Int when Char is transferred (1/2 config!)
    	U2STAbits.UTXINV = 0;	//Bit14 N/A, IRDA config
    	U2STAbits.UTXISEL0 = 0;	//Bit13 Other half of Bit15
    	//U2STAbits.notimplemented = 0;	//Bit12
    	U2STAbits.UTXBRK = 0;	//Bit11 Disabled
    	U2STAbits.UTXEN = 0;	//Bit10 TX pins controlled by periph
    	U2STAbits.UTXBF = 0;	//Bit9 *Read Only Bit*
    	U2STAbits.TRMT = 0;	//Bit8 *Read Only bit*
    	U2STAbits.URXISEL = 0;	//Bits6,7 Int. on character recieved
    	U2STAbits.ADDEN = 0;	//Bit5 Address Detect Disabled
    	U2STAbits.RIDLE = 0;	//Bit4 *Read Only Bit*
    	U2STAbits.PERR = 0;		//Bit3 *Read Only Bit*
    	U2STAbits.FERR = 0;		//Bit2 *Read Only Bit*
    	U2STAbits.OERR = 0;		//Bit1 *Read Only Bit*
    	U2STAbits.URXDA = 0;	//Bit0 *Read Only Bit*
    
    	IPC7 = 0x4400;	// Mid Range Interrupt Priority level, no urgent reason
    
    	IFS1bits.U2TXIF = 0;	// Clear the Transmit Interrupt Flag
    	IEC1bits.U2TXIE = 0;	// Enable Transmit Interrupts
    	IFS1bits.U2RXIF = 0;	// Clear the Recieve Interrupt Flag
    	IEC1bits.U2RXIE = 1;	// Enable Recieve Interrupts
    
    	U2MODEbits.UARTEN = 1;	// And turn the peripheral on
    
    	U2STAbits.UTXEN = 1;
    	// I think I have the thing working now.
    }
    
    void __attribute__ ((interrupt, no_auto_psv)) _U2RXInterrupt(void)
    {
    	IFS1bits.U2RXIF = 0;
                				// read RX regbuffer if output buffer is not yet full
    	temp_buffer = U2RXREG;
    	bufferRx[compteur] = temp_buffer;
    	compteur++;
    
            if( compteur>=10 )
                    {
                        compteur=0;
                    }
    }
    void __attribute__ ((interrupt, no_auto_psv)) _U2TXInterrupt(void)
    {
    
        U2TXREG = bufferTx[z];
    
        z++;
        if(z>=10)
        {
            z=1;
            IEC1bits.U2TXIE = 0;
        }
        IFS1bits.U2TXIF = 0;
    }
    
    /*---------------------------------------------------------------------
      Function Name: _T2Interrupt
      Description:   interruption lié au timer, doit faire clignoter une led
                     chaque fois qu'on arrive dans cette boucle
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
     void __attribute__((interrupt,no_auto_psv)) _T2Interrupt( void )
     {
        int i;
        _T2IF = 0;
    
        count_1s++;
    
        for (i=0;i<10;i++)
        {
            bufferTx[i]=bufferRx[i];
        }
        if (count_1s==30000)
        {
       while(!U2STAbits.TRMT);
           if (IEC1bits.U2TXIE == 0)
                 {
                      IFS1bits.U2TXIF = 0;
                      IEC1bits.U2TXIE = 1;
                      U2TXREG = bufferTx[0];
                      _LATA1=~_LATA1;
                 }
       count_1s=0;
        }
        TMR2=0;
        T2CONbits.TON = 1;
    
     }

  14. #13
    antek

    Re : dspic33EP UART pin

    Citation Envoyé par marc64ab Voir le message
    oui le pic est sur un module enfichable que j'insère directement sur la carte Explorer 16.
    C'est ce module-ci qui m'intéresse !

  15. #14
    invite21ace5e2

    Re : dspic33EP UART pin

    Autant pour moi ;

    voici le lien de la datasheet : http://docs-europe.electrocomponents...6b812a2821.pdf

    et voici le lien de ce que j'ai acheté : http://fr.rs-online.com/web/p/kits-d...iques/7983176/

  16. #15
    antek

    Re : dspic33EP UART pin

    La pin 49 est entre autres la RPI24 remappable (voir PPS dans la doc). Il faut donc que tu affectes le Rx souhaité vers cette pin.
    La pin 50 est une RPx, idem.

  17. #16
    invite21ace5e2

    Re : dspic33EP UART pin

    ah ok je connaissais pas ce type de sortie je vais voir ce que je peux en faire je vous tiens au jus,

    Merci
    Marc

  18. #17
    RISC

    Re : dspic33EP UART pin

    Salut,

    Sur la page de la carte EXPLORER16, il existe un projet qui gère un grand nombre de PIMs prévus pour cette carte.
    Ce projet comporte 2 applications qui ont un grand nombre de configurations pour les différents PIMs dont celui du dsPIC33EP512GM710.

    Le PPS (peripheral pin select) permet de choisir sur quelles broches tu veux connecter les périphériques.

    a+

  19. #18
    invite21ace5e2

    Re : dspic33EP UART pin

    Bonjour,

    J'ai effectuer les changements de périphériques avec PPS. Vous les trouverez dans la fonction "ConfigureI0Functions" du programme ci-dessous.
    Realterm me dit que le port sur lequel j'ai plugger le câble RS232 est déjà ouvert. Savez-vous ce que cela veut dire ?
    La communication ne se fait toujours pas ...

    Merci
    Marc

    Code:
    #include <p33EP512GM710.h>
    #include <math.h>
    #include<stdbool.h>
    
    #define FP 70000000
    #define BAUDRATE 115200
    #define BRGVAL ((FP/BAUDRATE)/16)-1
    
    
    //--- Configuration ---//
    _FOSCSEL( FNOSC_PRI );                              // Select Primary Oscillator (Posc) at POR (Power-on Reset)
    _FOSC( POSCMD_XT & OSCIOFNC_OFF & FCKSM_CSECMD );   // Configure Posc in HS mode, Enable clock switching
    _FWDT( WDTPOST_PS32768 & FWDTEN_OFF );
    _FICD( JTAGEN_OFF );
    
    //--- prototype de fonction ---//
    
    void Init_Osci(void);
    void Init_Timer2(void);
    void Init_Port(void);
    void wait(void);
    void InitUART2(void);
    void ConfigureI0Functions(void);
    
    #define TRUE	1
    #define FALSE	0
    
    bool Config_OK=0, Start=0;
    int z=1, i=1, j=0, count_1s=0;
    char bufferTx[10];
    char bufferRx[10];
    int compteur=10;
    char buffer[10];
    char temp_buffer;
    
    unsigned char S3Flag, S4Flag, S5Flag, S6Flag;
    
    int main(void)
    {
    
        RCONbits.SWDTEN=0;          // Disable Watch Dog Timer
    
        Init_Port();
        Init_Osci();                // Oscilator initialisation
        Init_Timer2();              // Timer2 initialisation
        InitUART2();                // Initialize UART2 for 115200,8,N,1 TX/RX
        ConfigureI0Functions();     // Configure les I/O de l'UART
    
    
    
                                bufferTx[0]='$';
                                bufferTx[1]='1';
                                bufferTx[2]='2';
                                bufferTx[3]='3';
                                bufferTx[4]='4';
                                bufferTx[5]='5';
                                bufferTx[6]='6';
                                bufferTx[7]='7';
                                bufferTx[8]='8';
                                bufferTx[9]='9';
    
    
    
    
                        if (IEC1bits.U2TXIE == 0)
                            {
                                IFS1bits.U2TXIF = 0;
                                IEC1bits.U2TXIE = 1;
                                U2TXREG = buffer[0];
    
                            }
    
    	while(1)
            {
                
            }
    }
    
    /*---------------------------------------------------------------------
      Function Name: newparametre
      Description:   nouveau parametre PWM
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void wait (void)
    {
        long h=900000;
        while(h)
        {
            h--;
        }
    }
    
    
    /*---------------------------------------------------------------------
      Function Name: Init_Osci
      Description:   Initialize oscillator
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void Init_Osci( void )    // Fonction pour initialiser l'oscillateur
    
    {
         // Configure Oscillator to operate the device at 70Mhz
        // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
        // Fosc= 8M*245/(2*7)=140Mhz for 8M input clock
    
        // Configure PLL prescaler, PLL postscaler, PLL divisor
        CLKDIV = 0x05; 			// N2 = 7 N1=2
        PLLFBD = 0xF3;			// M = 245
    
        //  Clock switching to incorporate PLL (NOSC=0b011)
        __builtin_write_OSCCONH(0x03); 		// Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011)										// configuration du registre NOSC (OSCCON) -->
        __builtin_write_OSCCONL(0x01);		// Start clock switching
    
        // Wait for Clock switch to occur
        while(OSCCONbits.COSC != 0b011);
    
        // Wait for PLL to lock
        while(OSCCONbits.LOCK != 1);
    }
    
    
    /*---------------------------------------------------------------------
      Function Name: Init_Port
      Description:   Initialize I/O
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void Init_Port( void )      // Fonction pour initialiser les I/O
    
    {
        // S3 (portD Pin 6, chosen as trigger for sending 'M' to UART)
        // S6 (portC Pin 9, chosen as trigger for sending 'C' to UART)
        // S5 (portF Pin 7, chosen as trigger for sending 'H' to UART)
        // S4 (portD Pin 13, chosen as trigger for sending 'P' to UART)
        ANSELA = 0;
        ANSELC = 0;
        ANSELD = 0;
        ANSELF = 0;
    
        // we need to config the pin as DIGITAL
        TRISD = 0x2040;         // D6,D13 inputs
        TRISFbits.TRISF7 = 1;   // f7 is input
        TRISCbits.TRISC9 = 1;   //C9 is input
        TRISBbits.TRISB4 = 0;   //B4 as output
        TRISAbits.TRISA8 = 1;   //A8 as input
        S3Flag = S4Flag = S5Flag = S6Flag = 0;	// Some Debounce Flags
    }
    
    
    /*---------------------------------------------------------------------
      Function Name: Init_Timer2
      Description:   Initialize Timer2 10kHz ---> 100us
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void Init_Timer2( void )    // Initialize Timer2
    
    {
        T2CONbits.TON = 0;      // Disable Timer
        T2CONbits.T32 = 0;      // Timer 16 bits
        T2CONbits.TCS = 0;      // Select internal instruction cycle clock (Fosc/2)
        T2CONbits.TGATE = 0;    // Disable Gated Timer mode
        T2CONbits.TCKPS = 0;    // Select 1:1 Prescaler (70MHz--->14285ps)
    
    
        IFS0bits.T2IF = 0;      // Reset Timer2 interrupt flag
        IPC1bits.T2IP = 2;      // Timer2 Interrupt priority level=4
        IEC0bits.T2IE = 1;      // Enable Timer2 interrupt
    
        TMR2= 0;                // Clear timer register
        PR2 = 6960;             // Load the period value (100us/14285ps=7000)   6960 pour l'ajustement
    
        T2CONbits.TON = 1;      // Enable Timer2 and start the counter
    }
    
    
    
    /*---------------------------------------------------------------------
      Function Name: InitUART1
      Description:   Initialisation de l'UART
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void InitUART2()
    {
          // This is an EXAMPLE, so brutal typing goes into explaining all bit sets
    
    	// The HPC16 board has a DB9 connector wired to UART2, so we will
    	// be configuring this port only
    
    	// configure U2MODE
    	U2MODEbits.UARTEN = 0;	// Bit15 TX, RX DISABLED, ENABLE at end of func
    	//U2MODEbits.notimplemented;	// Bit14
    	U2MODEbits.USIDL = 0;	// Bit13 Continue in Idle
    	U2MODEbits.IREN = 0;	// Bit12 No IR translation
    	U2MODEbits.RTSMD = 0;	// Bit11 Simplex Mode
    	//U2MODEbits.notimplemented;	// Bit10
    	U2MODEbits.UEN = 0;		// Bits8,9 TX,RX enabled, CTS,RTS not
    	U2MODEbits.WAKE = 0;	// Bit7 No Wake up (since we don't sleep here)
    	U2MODEbits.LPBACK = 0;	// Bit6 No Loop Back
    	U2MODEbits.ABAUD = 0;	// Bit5 No Autobaud (would require sending '55')
    	U2MODEbits.URXINV = 0;	// Bit4 IdleState = 1  (for dsPIC)
    	U2MODEbits.BRGH = 0;	// Bit3 16 clocks per bit period
    	U2MODEbits.PDSEL = 0;	// Bits1,2 8bit, No Parity
    	U2MODEbits.STSEL = 0;	// Bit0 One Stop Bit
    
    	// Load a value into Baud Rate Generator.  Example is for 9600.
    	// See section 19.3.1 of datasheet.
    	//  U2BRG = (Fcy/(16*BaudRate))-1
    	//  U2BRG = (37M/(16*9600))-1
    	//  U2BRG = 240
    	U2BRG = BRGVAL;	// 40Mhz osc, 9600 Baud,
    
    	// Load all values in for U1STA SFR
    	U2STAbits.UTXISEL1 = 0;	//Bit15 Int when Char is transferred (1/2 config!)
    	U2STAbits.UTXINV = 0;	//Bit14 N/A, IRDA config
    	U2STAbits.UTXISEL0 = 0;	//Bit13 Other half of Bit15
    	//U2STAbits.notimplemented = 0;	//Bit12
    	U2STAbits.UTXBRK = 0;	//Bit11 Disabled
    	U2STAbits.UTXEN = 0;	//Bit10 TX pins controlled by periph
    	U2STAbits.UTXBF = 0;	//Bit9 *Read Only Bit*
    	U2STAbits.TRMT = 0;	//Bit8 *Read Only bit*
    	U2STAbits.URXISEL = 0;	//Bits6,7 Int. on character recieved
    	U2STAbits.ADDEN = 0;	//Bit5 Address Detect Disabled
    	U2STAbits.RIDLE = 0;	//Bit4 *Read Only Bit*
    	U2STAbits.PERR = 0;		//Bit3 *Read Only Bit*
    	U2STAbits.FERR = 0;		//Bit2 *Read Only Bit*
    	U2STAbits.OERR = 0;		//Bit1 *Read Only Bit*
    	U2STAbits.URXDA = 0;	//Bit0 *Read Only Bit*
    
    	IPC7 = 0x4400;	// Mid Range Interrupt Priority level, no urgent reason
    
    	IFS1bits.U2TXIF = 0;	// Clear the Transmit Interrupt Flag
    	IEC1bits.U2TXIE = 0;	// Enable Transmit Interrupts
    	IFS1bits.U2RXIF = 0;	// Clear the Recieve Interrupt Flag
    	IEC1bits.U2RXIE = 1;	// Enable Recieve Interrupts
    
    	U2MODEbits.UARTEN = 1;	// And turn the peripheral on
    
    	U2STAbits.UTXEN = 1;
    	// I think I have the thing working now.
    }
    
    void __attribute__ ((interrupt, no_auto_psv)) _U2RXInterrupt(void)
    {
    	IFS1bits.U2RXIF = 0;
                				// read RX regbuffer if output buffer is not yet full
    	temp_buffer = U2RXREG;
    	bufferRx[compteur] = temp_buffer;
    	compteur++;
    
            if( compteur>=10 )
                    {
                        compteur=0;
                    }
    }
    void __attribute__ ((interrupt, no_auto_psv)) _U2TXInterrupt(void)
    {
    
        U2TXREG = bufferTx[z];
    
        z++;
        if(z>=10)
        {
            z=1;
            IEC1bits.U2TXIE = 0;
        }
        IFS1bits.U2TXIF = 0;
    }
    /*---------------------------------------------------------------------
      Function Name: ConfigureI0Functions
      Description:   Permet de configuer les entrées/sorties de l'UART2 sur les 
                     pins sélectionnées (pin 49 et 50), correspondant à la com RS232
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
    void ConfigureI0Functions()
    {
        __builtin_write_OSCCONL(OSCCON & ~(1<<6));
        RPINR19bits.U2RXR = 0x18;     // Assigne U2RX à la pin 49 (RPI24)
        RPOR1bits.RP36R = 3;          // Assigne U2TX à la pin 50 (RP36)
        __builtin_write_OSCCONL(OSCCON | (1<<6));
    }
    /*---------------------------------------------------------------------
      Function Name: _T2Interrupt
      Description:   interruption lié au timer, doit faire clignoter une led
                     chaque fois qu'on arrive dans cette boucle
      Inputs:        None
      Returns:       None
    -----------------------------------------------------------------------*/
     void __attribute__((interrupt,no_auto_psv)) _T2Interrupt( void )
     {
        int i;
        _T2IF = 0;
    
        count_1s++;
    
        for (i=0;i<10;i++)
        {
            bufferTx[i]=bufferRx[i];
        }
        if (count_1s==30000)
        {
       while(!U2STAbits.TRMT);
           if (IEC1bits.U2TXIE == 0)
                 {
                      IFS1bits.U2TXIF = 0;
                      IEC1bits.U2TXIE = 1;
                      U2TXREG = bufferTx[0];
                      _LATA1=~_LATA1;
                 }
       count_1s=0;
        }
        TMR2=0;
        T2CONbits.TON = 1;
    
     }

  20. #19
    RISC

    Re : dspic33EP UART pin

    Salut,
    A ce stade il faut vérifier ou se trouve le PB...coté dsPIC (PB soft) ou coté PC (programme terminal).
    Si tu as un oscillo, commence par regarder si ton message sors sur le connecteur RS232. si tu ne vois rien c'est probablement que ton initialisation de l'UART n'est pas correcte.

    Ce que je ferai à ta place est de vérifier la liason RS232 dsPIC <==> PC en utilisant le PIM dsPIC33FJ256GP710A.
    C'est facile à faire car il existe des exemples tous faits (Code Examples) qui sont écrits pour ce dsPIC.
    Pour l'UART, il s'agit du code example CE137 : http://ww1.microchip.com/downloads/e...MA_14aug09.zip
    (Il faut bien sûr importer ce projet MPLAB sous MPLAB X pour qu'il soit converti.)

    Tu peux t'inspirer des code example CE414 et CE437 qui utilisent l'UART pour le dsPIC33EP512MU810 qui est très proche de ton dsPIC (je pense que la partie UART est exactement la même).

    a+

  21. #20
    antek

    Re : dspic33EP UART pin

    Citation Envoyé par marc64ab Voir le message
    ah ok je connaissais pas ce type de sortie je vais voir ce que je peux en faire je vous tiens au jus
    Pour précision, ce peuvent être aussi bien des entrées que des sorties.

  22. #21
    bisou10

    Re : dspic33EP UART pin

    1) Il faut bien voir les registres PPS dans la DS pour correctement faire matcher les pins d'uart

    2) Tu peux aussi utiliser les APIs Peripherals (récemment séparées du compilateur un module spécifique) plutot que de recoder la liaison UART: #include <uart.h>

Discussions similaires

  1. sortie 5V dspic33EP
    Par invite21ace5e2 dans le forum Électronique
    Réponses: 13
    Dernier message: 21/05/2015, 07h46
  2. uart
    Par invite38dd7265 dans le forum Électronique
    Réponses: 2
    Dernier message: 19/03/2015, 22h05
  3. PIC et I2C vs UART
    Par invite220a379c dans le forum Électronique
    Réponses: 3
    Dernier message: 15/07/2009, 11h36
  4. bus i2c ou UART et RTC
    Par invite86ffa844 dans le forum Électronique
    Réponses: 7
    Dernier message: 16/11/2008, 13h31
  5. Usb < -- > Uart
    Par invitee5173b0d dans le forum Électronique
    Réponses: 0
    Dernier message: 22/04/2008, 13h29
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...