Pic XC8 et instruction printf
Répondre à la discussion
Affichage des résultats 1 à 9 sur 9

Pic XC8 et instruction printf



  1. #1
    ueihttam

    Pic XC8 et instruction printf


    ------

    Bonjour,

    Je fais remonter ce post car je cherche à récupérer des infos provenant de l'USART d'un PIC18F4553.
    Je cherche tout d'abord à récupérer sur PuTTY un simple Hello World.
    Voici à quoi ressemble mon programme :

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include<pic18f4553.h>
    #include <plib/usart.h>
    
    #include <xc.h>
    
    #pragma config... (je vous passe les lignes qui vont de config1l à config7h)
    
    #define IRCF.OSCCON=0x06 //equivaut à 4MHz
    
    void putch (char c)
    {
       while (!TRMT);
       TXREG = c;
    }
    
    void main() {
            double  y=3014151;
    	TRISC=0;
    	//OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON &
    	//USART_ASYNCH_MODE & USART_EIGHT_BIT &
    	//USART_CONT_RX & USART_BRGH_LOW, 31);
    
    
        //Activer les modes d'opération
        SYNC = 0;                                     //Setting Asynchronous Mode, ie UART
        SPEN = 1;                                     //Enables Serial Port
        TRISC7 = 1;                                   //As Prescribed in Datasheet
        TRISC6 = 1;                                   //As Prescribed in Datasheet
        //initialiser le débit à 9600 bauds
        BRGH = 1;
        SPBRG = 25;
        //CREN = 1;                                     //Enables Continuous Reception
        TXEN = 1;                                     //Enables Transmission
    
            y=1.0/3.0;
    	printf("Hello, world by prinf %10.6f!\n\r",y);
            putsUSART("Hello, world by putsUSART !\n\r");
    	while(1);
    }
    Voilà, les valeurs de BRGH et SPBRG ont été trouvé par rapport à la datasheet, pour avoir une com de 9600 baud.

    J'utilise un câble FTDI TTL-232R-3V3-WE, windows me détecte mon matériel et le met en COM5.
    Dans PuTTY, je règle la liaison série avec les paramètres suivants :
    Ligne : COM5
    Vitesse : 9600
    Data bits : 8
    Stop bits : 1 (j'ai essayé d'en mettre 2 vu que je ne me sers pas du 9ème bit pour la parité mais même soucis)
    Pas de parité ni de contrôle de flux

    Quand je lance le terminal, j'obtiens ceci :
    Nom : PuTTY.png
Affichages : 104
Taille : 16,9 Ko

    Ca ressemble bien à un problème de config entre le PIC et PuTTY non ? Quand je fais un reset du PIC, je remarque que c'est le même motif qui est envoyé.

    Merci de votre aide.

    -----
    Dernière modification par Antoane ; 06/03/2015 à 17h10. Motif: Ajout balises [code]

  2. #2
    Antoane
    Responsable technique

    Re : Pic XC8 et instruction printf

    Bonsoir,
    Citation Envoyé par ueihttam Voir le message
    Je fais remonter ce post car je cherche à récupérer des infos provenant de l'USART d'un PIC18F4553.

    Pour une nouvelle question, il convient d'ouvrir une nouvelle discussion, c'est chose faite à présent.

    Pense également à utiliser la balise [code] [/code] pour poster ton code : cela le rend plus lisible, en préservant l'indentation.
    Deux pattes c'est une diode, trois pattes c'est un transistor, quatre pattes c'est une vache.

  3. #3
    ueihttam

    Re : Pic XC8 et instruction printf

    Bonjour,

    Ok, merci pour la nouvelle discussion.

    Des idées ?

  4. #4
    RISC

    Re : Pic XC8 et instruction printf

    Salut,

    Utilises-tu un quartz externe ou l'horloge interne du PIC ?

    Fais voir tes bits de configuration.

    A+

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

    Re : Pic XC8 et instruction printf

    Bonjour,

    J'utilise l'horloge interne du PIC.
    Voici le détail des bits de configuration ; les lignes de codes sont placées entre le #include <xc.h> et le #define IRCF.OSCCON=0x06 //equivaut à 4MHz

    Code:
    //PIC18F4553
    // #pragma config statements should precede project file includes.
    // Use project enums instead of #define for ON and OFF.
    
    // CONFIG1L
    #pragma config PLLDIV = 1       // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
    #pragma config CPUDIV = 0       // System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
    #pragma config USBDIV = 0       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
    
    // CONFIG1H
    #pragma config FOSC = INTOSCIO_EC// Oscillator Selection bits (Internal oscillator, port function on RA6, EC used by USB (INTIO))
    #pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
    #pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
    
    // CONFIG2L
    #pragma config PWRT = ON        // Power-up Timer Enable bit (PWRT enabled)
    #pragma config BOR = OFF        // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
    #pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting)
    #pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)
    
    // CONFIG2H
    #pragma config WDT = ON         // Watchdog Timer Enable bit (WDT enabled)
    #pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)
    
    // CONFIG3H
    #pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
    #pragma config PBADEN = ON      // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
    #pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
    #pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
    
    // CONFIG4L
    #pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
    #pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
    #pragma config ICPRT = OFF      // Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled)
    #pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
    
    // CONFIG5L
    #pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
    #pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
    #pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
    #pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)
    
    // CONFIG5H
    #pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
    #pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)
    
    // CONFIG6L
    #pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
    #pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
    #pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
    #pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)
    
    // CONFIG6H
    #pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
    #pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
    #pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
    
    // CONFIG7L
    #pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
    #pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
    #pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
    #pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)
    
    // CONFIG7H
    #pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)
    Merci de votre aide.

  7. #6
    invite03481543

    Re : Pic XC8 et instruction printf

    Bonsoir,

    essaye en mettant le watchdog OFF, et en enlevant les commentaires sur OpenUSART(....) ça ne peut pas fonctionner sinon.

  8. #7
    ueihttam

    Re : Pic XC8 et instruction printf

    Bonjour,

    Après quelques essais, il s'est avéré que la clock interne était mal configurée. Le #define IRCF.OSCCON=0x06 //equivaut à 4MHz n'avait pas d'influence, même si je changeais la valeur de IRCF.OSCCON
    J'ai donc intégré dans le main les lignes suivantes :
    Code:
    IDLEN = 0;
    IRCF2=1;
    IRCF1=1;
    IRCF0=0;
    OSTS = 0;
    IOFS = 0;
    SCS1=0;
    SCS0=0;
    Voilà, la com avec PuTTY fonctionne correctement maintenant

    Merci pour votre aide.

  9. #8
    ueihttam

    Re : Pic XC8 et instruction printf

    Et j'ai oublié de dire aussi que j'ai modifié le TRISC6 à 0 pour configurer le TX en sortie.

  10. #9
    RISC

    Re : Pic XC8 et instruction printf

    Salut,
    La précision de l'oscillateur interne n'est pas suffisante...Commence par mettre un quartz.
    Une liaison série DOIT avoir un oscillateur garanti à +/-2%, ce qui n'est pas le cas pour le PIC18F4553
    a+

Discussions similaires

  1. Compilateur Pic XC8 et instruction printf
    Par jhl14 dans le forum Électronique
    Réponses: 5
    Dernier message: 23/04/2014, 05h57
  2. Bug avec un printf()
    Par ti7bo7 dans le forum Programmation et langages, Algorithmique
    Réponses: 8
    Dernier message: 30/11/2012, 08h59
  3. printf() icd3 mplab uart1A
    Par pseudoguyanais dans le forum Électronique
    Réponses: 5
    Dernier message: 23/09/2010, 09h57
  4. atmel AT91SAM7X256 et printf ...
    Par invite099898f8 dans le forum Électronique
    Réponses: 4
    Dernier message: 21/04/2008, 08h10
  5. printf pour LCD
    Par Jack dans le forum Électronique
    Réponses: 3
    Dernier message: 10/08/2004, 16h21
Découvrez nos comparatifs produits sur l'informatique et les technologies.