Problème Résistances PULL UP sur sorties PIC18F45K22 - Page 2
Répondre à la discussion
Page 2 sur 2 PremièrePremière 2
Affichage des résultats 31 à 45 sur 45

Problème Résistances PULL UP sur sorties PIC18F45K22



  1. #31
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22


    ------

    @Tonave 72 : je ne peux pas actuellement voir ton schéma puisqu'il n'a pas été validé par les modérateurs. Je regarde ça dès que possible. Merci pour ta réponse.

    @paulfjujo : je viens de faire quelques essais en mode débug. Je suis équipé d'une carte PICDEM2 et d'un PICKIT3. Donc quand j'utilise ton scénario du post #26, j'obtiens ça : 4,57V au repos, 4,86V PIC débranché, 4,57 capteur débranché. Et quand je fais le même scénario mais avec la pin en entrée, j'obtiens ça : 2,10V au repos, 4,85 PIC débranché, 2,11V capteur débranché. Ce qui montre bien que mon PIC fait chuter ma tension... Et donc le problème est toujours là .

    -----

  2. #32
    paulfjujo

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    mais avec la pin en entrée, j'obtiens ça : 2,10V au repos,
    Quelle est ta valeur de R pull up ?
    En mode entree le buffer est de type TTL .. et mini niveau Haut TTL devrait etre >= 2,7V
    soit la resistance de pull up est trop elevée , ce qui fait baisser la tension à cause du courant d'entree .
    Tu peux meme essayer avec R pull up = 2,7K !

    Vu le nombre impressionnant de combinaisons possibles d'affection de ces 2 pins B1 et B2
    Voir si la Config Bits n'interfere pas,
    avec les Entrees ANA
    avec les comparateurs !
    avec les interruptions

  3. #33
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    D'après ce document, les résistance de pull up du bus doivent être comprise entre 4,7k et 100k. Ce sont des données constructeur de mon capteur, que je me dois de respecter ! Pour ma part, n'ayant pas de résistance de 4,7k j'ai mis deux résistances de 10k en parallèle, ce qui se rapproche de mon 4,7k minimum.

  4. #34
    paulfjujo

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Je viens de faire un test sur un PIC18F46K22 , en mettant 2 R de 6.2K en pull up sur B2 et B1
    PortB en sortie avec FF
    je mets à 0 la sortie B2 => 0,02V en sortie
    je relis le port B => 251 ( normal car B2 à Zero )
    je passe B2 en mode Entree
    B2 => 4.95V !
    je relis le portB => 255 ( normal car B2 est à 1 via la Pull up).

    Est-tu certain de ta CONFIG BiTS !
    est-tu certain de tes 2 10K ohms en // ?
    ci joint mon programme de test
    encombré , mais avec un environnement qui MARCHE..


    Code:
    //
    //03/07/2012
    //18F46K22_test_B1_B2.c
    //http://forums.futura-sciences.com/electronique/549300-probleme-resistances-pull-up-sorties-pic18f45k22.html
    
    #include "p18f46k22.h"
    
     /*  HARDWARE
     =========== HARDWARE ====================
    27 pf  Q=20Mhz 27pF
    Interface 2T pour liaison UART TTL <-> RS232 38400 bauds
    LCD 2x16 cars
    
    PIC 18F46K22  40 pins DIP
    PortB
     RB0  33   input for IRC5 en interrupt TSOP1736
     RB1  34   SCL  -- pull up de 4,7K
     RB2  23   SDA  -- pull up de 4,7K
     RB3  24
     RB4  25
     RB5  26
     RB6  27  ICSP_Clck   Bleu foncé    Pin5 Pickit3
     RB7  28  ICSP_Data   Bleu clair    Pin4 Pickit3
    
    
    PORTA
     RA0   2  Analog Input
     RA1   3  Analog Input
     RA2   4  Analog Input
     RA3   5  input
     RA4   6  Output .. Led .. 390 ohms +5V
     RA5   7  Output
     RA6   8  ----- Quartz 20Mhz   C=22pF -- Gnd
     RA7   9  ------ Quartz ---    C=22pF -- Gnd
    
    PORTC
     RC0   15
     RC1   16
     RC2   17
     RC3   18
     RC4   23  
     RC5   24  
     RC6   25  TX  RS232   UART1 Harware
     RC7   26  RX  RS232   UART1 Hardware
    
    PORTD
     RD0   19
     RD1   20
     RD2   21
     RD3   22
     RD4   27   
     RD5   28   
     RD6   29  
     RD7   30   
         
    
    PORTE
     RE0   8
     RE1   9
     RE2   10
     RE3   1   MCLR via Rserie=6,8K to +5V 
          1   --- jaune -- VPP/MCLR ---  pin1 Pickit3
     VSS  12  ---- blanc ------Gnd-----  pin3 Pickit3
     VSS  12  ----  GND Power
     VSS  31  ----  GND Power
     VDD  11  ----  +5V Power
     VDD  32  ----  +5V Power
    
    ====================================================
    */
    
    
    #include "stdio.h"
    #include <stdlib.h>
    #include <delays.h>
    #include <string.h>
    #include <usart.h>   // pour fonctions UART
    #include <adc.h>
    #include <ctype.h>
    #include <portb.h>
    #include <timers.h>
    #include <math.h>
    
    #ifdef OSCILLATEUR_INTERNE
    #pragma config FOSC = INTIO67, FCMEN = OFF, PLLCFG=OFF
    #else
    #pragma config FOSC = HSHP, PLLCFG=OFF, PRICLKEN=ON ,FCMEN=OFF
    #endif
    #pragma config IESO=OFF,PWRTEN=ON,BOREN=OFF,WDTEN=OFF,CCP2MX=PORTC1
    #pragma config PBADEN=OFF,CCP3MX=PORTE0,T3CMX=PORTC0,P2BMX=PORTC0
    #pragma config MCLRE=EXTMCLR,STVREN=OFF,LVP=ON,XINST=OFF,DEBUG=OFF
    #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
    #pragma config CPB = OFF, CPD = OFF
    #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
    #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
    #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
    #pragma config EBTRB = OFF
    
    // config vue sur Pickit3 : 2200 3C18 9900 0084 C00F E00F 400F
    
    #ifndef Byte
    #define Byte unsigned char
    #endif
    
    
    #define DureeCycle 10 // * 1 diziemes de secondes => 1,0sec
    
    #define CLS 12
    #define BS 8
    #define TAB 9
    #define CR 13
    #define LF 10
    #define Bell 7
    #define ON 0	// logique inverse avec led tiree au +5V
    #define OFF 1
    
    #define Led_Rouge    PORTAbits.RA4
    #define Allume 0
    #define Eteint 1
    #define MAX_LEN	80		// taille buffer
    
    
    /*	Variables globales */
    unsigned int count;
    char Texte[MAX_LEN];
    char *txt;
    unsigned char Entree[17]="1234567890123456";
    unsigned char *valtxt;
    char buffer[40]="00000000000000000000000";	// buffer de reception
    char received;
    char *ptlec;		// pointeur de lecture
    char *ptecr;		// pointeur d'ecriture
    unsigned int CptCars;
    unsigned int SaisieOk;
    //unsigned char Drapeaux ;     // 8 flags
    struct chbits {
                     unsigned running:1;
                     unsigned standby:1;
                     unsigned elligible:1;
                     unsigned Accumule:1;
                     unsigned Blc:1;
                     unsigned OneShot:1;
                     unsigned Fill:1;
                     unsigned Lcd:1;
                   } Drapeaux;
    
    #define OUT_RS232 Drapeaux.Lcd=0;
    #define OUT_LCD Drapeaux.Lcd=1;
    
    unsigned int TimeEcoule;
    Byte receive;
    char error;
    char EtatCf;
    signed char Ve;
    unsigned int  NbMes;
    Byte Allume_led;
    Byte Dummy;
    unsigned int i,j,k,l ;
    unsigned char s_count = 0;
    unsigned int M;
    unsigned int INT_TEMP;      // temperature interne via diode
    float F;
    unsigned long L1,L2;
    rom const char chaine0[]="ESC pour sortir\r";
    rom const char chaine1[]="Port comm 38400 ouvert ... String en ROM \r\n";
    rom const char chaine2[]="MPLAB v8.84 C18 : 18F46K22_test_b1_b2.c\r\n";
    rom const char chaine3[]="fin normale\r";
    rom const char chaine4[]="J= ";
    rom char *RS_Str[]={chaine0,chaine1,chaine2,chaine3,chaine4 };
    
    #pragma romdata EEP_=0xF00000
    
    rom unsigned char EEPROM_data [][32] ={
          //   1234567890123456789012345678901
              "Projet:18F46K22_tests.mcp     \r",//0  avec terminateur zero
              "Port Com 38400bds & Init HARD.\r",//20  avec terminateur zero
              "Boucle en 1 Sec   <ESC> exit  \r",//40  avec terminateur zero
              "Avec UART1 HARDWARE.......... \r",//60  avec terminateur zero
              "paulfjujo@free.fr        \r\n",//80   sans terminateur zero
              "MPLAB IDE V8.63  \r\n",
              "C18 v3.37.01   \r\n",0
              };
    #pragma romdata
    
    //--------- RS232 UART HARDWARE --------------
    
    void Init_UART1(void);
    int PutStr_RS(char *s);
    void Put_RS(char * untel);
    void CRLF();
    void Write_Word(unsigned int M,char Sign);
    void Tempo(long val);
    void Remplis_N_blancs(Byte N);
    void Init_Hardware(void) ;
    
    void InterruptHandlerHigh (void);
    
    //gestionnaire d'interruption
    //------------------------------
    // High priority interrupt vector
    #pragma code InterruptVectorHigh = 0x08
    void InterruptVectorHigh (void)
    {
      _asm
        goto InterruptHandlerHigh //jump to interrupt routine
      _endasm
    }
    
    
    // High priority interrupt routine
    #pragma code
    #pragma interrupt InterruptHandlerHigh
    void InterruptHandlerHigh ()
    {
      static char i ; // doit ętre statique pour conserver sa valeur entre les IT
      char C ;
    //======== SERIAL======================
    if(PIR1bits.RCIF) // si un car arrive
       {
       C =Read1USART(); // le lire => RAZ  RCIF
       if(RCSTAbits.FERR || RCSTAbits.OERR)
         {
          RCSTAbits.CREN = 0 ; RCSTAbits.CREN= 1 ;
         }
        while(Busy1USART()); // par sécurité
        if (PORTBbits.RB1==0) Write1USART(C); // echo
         if( C == BS)
            {
             if(i>0){
                 i--;  }
            }
          else
          {
          if(C != CR && i<MAX_LEN)
          {
            buffer[i++]=C ; // stockage
            }else
            {
             buffer[i]='\0'; // fin de chaîne si CR
             i=0;
             received =1;
           }
          }
        }
    } // fin de routine interrupts
    
    
    void Init_UART1(void)
    {
    // USART_BRGH_HIGH,32
    // init 38400Bd a 20Mhz
    // init 19200Bd a 10Mhz avec IT en rx
    // voir para 18.5 spec sheet DS41159B page 186
    Open1USART( USART_TX_INT_OFF &
    USART_RX_INT_ON &
    USART_ASYNCH_MODE &
    USART_EIGHT_BIT &
    USART_CONT_RX &
    USART_BRGH_HIGH,32  //  10 pour 115200 bds 20Mhz   was 32
    );
    INTCONbits.PEIE = 1 ; // autorisation des IT des périphériques
    INTCONbits.GIE = 0 ; // autorisation globale des IT
    }
    
    int PutStr_RS(char *s)
    {
    	int n;
    	for (n = 0; *s; n++, s++)
    	{
           	Put_RS(*s);
         	}
    	return n;
    }
    
    void Put_RS(char * untel)
    {
       	while(Busy1USART());
       	Write1USART(untel);
    }
    
    void CRLF()
    {
      Put_RS(CR);  Put_RS(LF);
      }
    
    void Write_Word(unsigned int M,char Sign)
    {
    unsigned int i,k,l;
    unsigned long M1;
     valtxt=&Entree[0];
     if (Sign>1) return;
     if (Sign==0)
      {       M1=(long)M;
            ultoa(M1,valtxt);
      }
      else itoa(M,valtxt);
     if (Drapeaux.Fill==1)
     {
      k=strlen(Entree);
      for (i=0;i<k;i++) Entree[4+Sign-i]=Entree[k-i-1];
      for (i=0;i<(5+Sign-k);i++)
      {if (Drapeaux.Blc==1) Entree[i]='0'; else Entree[i]=' ';}
     }
     Entree[5+Sign]=0;
     k=PutStr_RS(valtxt);
    }
    
    
    
     
    void Remplis_N_blancs(Byte N)
    {int i;
     for (i=0;i<N;i++)
     {
      Put_RS(' ');
     }
    }
    
    void Tempo(long val)
    {
    while(val>0){val--;}
    }
    
    
    //---- EEPROM PIC
    unsigned char EEPROM_Lect(unsigned char adrL) ; // lecture a l'adresse adrL
    void PrintOut_Eeprom_Msg(int PtrE);
    
    //------  EEPROM du PIC ---------------
    
    unsigned char EEPROM_Lect(unsigned char adrL) // lecture a l'adresse adrL
    {
    	EEADR=adrL;
    	EECON1bits.EEPGD=0;     // 0= adressage EEPROM
    	EECON1bits.CFGS=0;      // 0= acces data EEPROM
    	EECON1bits.RD=1;        // arme Lecture EEprom
    	 Tempo(1000L);
    	return(EEDATA);
    }
    
    
    void PrintOut_Eeprom_Msg(int PtrE)
    { int i;
      do
      {
      i = (int)EEPROM_Lect(PtrE);
      if ( i==0) break;
    
      Put_RS((Byte)i);
      PtrE++;
      if ( PtrE > 255) break;
       }
      while (i!=0)  ;
     Tempo(15000L);
    }
    
    
    void Init_Hardware()
     {
       ANSELB=0;              // No analog input,PortB digital
       PORTB = 0xFF;
       TRISBbits.TRISB0=1;   	// B0 <- IR input
       TRISBbits.TRISB1=0;   	// B1 output
       TRISBbits.TRISB2=0;   	// B2 output
       TRISBbits.TRISB3=1;		// B3 not used
       TRISBbits.TRISB4=1;		// B4 not used
       TRISBbits.TRISB5=1;		// B5 not used
       TRISBbits.TRISB6=1;      // B6 not used
       TRISBbits.TRISB7=1;      // B7 not used
       WPUB=0x02;               // any pin pull up
       INTCON2bits.RBPU=0;      // enable Pull-up
    
      RCONbits.IPEN=1   ; // enable priority levels
      RCONbits.SBOREN=0;  //  BOR disbled
      SLRCON=0; // standard rate for PORTA,B,C,D,E
     }
    
    
    
    void main()
    {
     ANSELB=0;              // No analog input,PortB digital
     PORTB = 0xFF;
     TRISB=0x00;
     SLRCON=0; // standard rate for PORTA,B,C,D,E
     OUT_RS232
     Drapeaux.Fill=1;
     Drapeaux.Blc=1;
     Init_UART1();
     Put_RS(CLS);
     Tempo(100000L) ;
    
     txt=&Texte[0];
     strcpypgm2ram(txt,RS_Str[2]);
     k=PutStr_RS(txt);
     Tempo(100000L) ;
    
     INTCONbits.GIE = 0;
     TRISBbits.TRISB1=0;   	// B1 output	
    while(1)
     {
     TRISBbits.TRISB2=0;   	// B2 output   
     PORTBbits.RB1=1;
     PORTBbits.RB2=0;   
     Put_RS('O');
     Put_RS('=');
     itoa(PORTB,txt);
     k=PutStr_RS(txt);
     Tempo(1000000L) ;
     CRLF();
     TRISBbits.TRISB2=1;   	// B2 input   
     Put_RS('I');
     Put_RS('=');
     itoa(PORTB,txt);
     k=PutStr_RS(txt);
     Tempo(1000000L) ;
     CRLF();
     
      }
    }

  5. #35
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Ca y est, lorsque je suis en entrée les résistances de pull up font leur travail et j'obtiens bien 4,86V sur mon entrée. Le problème venait d'un Jumper de ma carte qui était mal positionné... En tout cas merci pour ton investissement paulfjujo, c'est vraiment sympa.

    Maintenant tu penses que je devrais fonctionner de la même manière que dans le tutorial donné par amoniac précédemment ? C'est à dire, jouer avec le TRISB pour faire passer en entrer ou en sortie mes pins etc..

  6. #36
    paulfjujo

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    jouer avec le TRISB pour faire passer en entrer ou en sortie mes pins etc

    OUI !
    surtout que ta fonction actuelle read_SDA ne peut pas marcher .

  7. #37
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Pourquoi ça ?

  8. #38
    paulfjujo

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    voir post#22

  9. #39
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Ah oui, j'avais pris en compte hier du coup j'ai fait la modification.

    Mais me conseilles-tu de refaire l'ensemble du code moi même grâce au tutorial I²C, ou de me servir de celui proposé dans la note d'application que j'ai trouvé sur le site constructeur ? Qu'est-ce qui me fera gagner le plus de temps d'après toi ?

  10. #40
    paulfjujo

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Le tutorial I2C te permettra de faire les adaptations necessaires
    pour la gestion des pins ,
    mais la note d'application constructeur est là pour te faire gagner du temps.

    Il n'y a pas de reponse binaire !

    Si tu as le temps, refaire tout le code serait benefique car didactique
    et pour la maitrise complete du code ( en suposant qu'il donne les resultats escomptés)
    en t'appuyant sur la datasheet du composant et la description du protocole.

    Personnellement , je ferai un mixte :
    adaptation gestion des pins (tutorial) ... et usage du canevas software constructeur.

  11. #41
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    D'accord, ça à l'air d'être une démarche intéressante.

    Personnellement, pour le moment je ne cherche pas à maitriser le code à 100%, je souhaite juste que l'intégration du capteur fonctionne. Car je pense être pas mal en retard sur mon projet de stage de fin d'étude qui se termine le 31 août. =/

    En tout cas merci pour ton implication qui m'aura été vraiment d'une aide précieuse, car je n'ai pas l'aide que j'aurais souhaitée dans mon entreprise de stage... Je te tiendrais au courant de l'avancement sur ce point.

  12. #42
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Bonjour,

    Quelqu'un serait-il capable de me faire une exemple de calcul sur "d |= 1" svp ? Avec d étant un char.

    Par avance merci .

  13. #43
    paulfjujo

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Il te faudra reviser les fonctions de bases OR AND XOR .. !

    Pour la comprhension je prefer utiliser le mode long (normal) d'ecriture
    d= d | 1 ;
    pour la lisibilité et comprenette.

    il est preferable d'utiliser un unsigned char ..
    le OR permet de mettre à 1 un bit .. en l'occurence le bit 1
    le second parametre doit correspondre au poid du bit (ou des bits) à mettre à un.

    Exemple avec AND ext XOR ci dessous
    (c'est un fichier de test ! avec 2 petites routines pour afficher en hexa et binaire sans passer par des printf)

    Code:
    //http://www.edaboard.com/thread258142.html
    //03/07/2012
    // Pickit3 
    // TESTE OK  en lecture
    
    // C18 MPLAB
    // directory : _C18\MesProjets_C18\_18F46K22
    // Projet :_C18\MesProjets_C18\_18F46K22\18F46K22_test_RS232.mcp
    // Source : 18F46K22_test_RS232.c
    
    #include "p18f46k22.h"
    
    #include "stdio.h"
    #include <stdlib.h>
    #include <delays.h>
    #include <string.h>
    #include <usart.h>   // pour fonctions UART HARDWARE
    #include <adc.h>
    #include <ctype.h>
    #include <portb.h>
    #include <timers.h>
    #include <math.h>
    
    // configuration bits set in code !
    #ifdef OSCILLATEUR_INTERNE
    #pragma config FOSC = INTIO67, FCMEN = OFF, PLLCFG=OFF
    #else
    #pragma config FOSC = HSHP, PLLCFG=OFF, PRICLKEN=ON ,FCMEN=OFF
    #endif
    #pragma config IESO=OFF,PWRTEN=ON,BOREN=OFF,WDTEN=OFF,CCP2MX=PORTC1
    #pragma config PBADEN=OFF,CCP3MX=PORTE0,T3CMX=PORTC0,P2BMX=PORTC0
    #pragma config MCLRE=EXTMCLR,STVREN=OFF,LVP=ON,XINST=OFF,DEBUG=OFF
    #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
    #pragma config CPB = OFF, CPD = OFF
    #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
    #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
    #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
    #pragma config EBTRB = OFF
    
    // config vue sur Pickit3 : 2200 3C18 9900 0084 C00F E00F 400F
    
    #ifndef Byte
    #define Byte unsigned char
    #endif
    
    
    #define DureeCycle 10 // * 1 diziemes de secondes => 1,0sec
    
    #define CLS 12
    #define BS 8
    #define TAB 9
    #define CR 13
    #define LF 10
    #define Bell 7
    #define ON 0	// logique inverse avec led tiree au +5V
    #define OFF 1
    
    #define Led_Rouge    PORTAbits.RA4
    #define Allume 0
    #define Eteint 1
    
    #define MAX_LEN 80
    
    
    unsigned int  i,j,k;
    unsigned int dummy;
    unsigned int j1;
    unsigned int M;
    unsigned int BRG_REG;
    volatile int i1;
    volatile char  c1;
    volatile int count;
    long L;
    
    char Texte[MAX_LEN]="18F46K22 test RS232 C18\r\n 03/07/2012 rev a\n\r19200bds Quartz 10Mhz \r\n\0";
    char *txt=&Texte[0];
    char buffer[MAX_LEN]="00000000000000000000000";	// buffer de reception
    char received;
    
    //--------- RS232 UART HARDWARE --------------
    
    void Init_UART1(void);
    int PutStr_RS(char *s);
    void Put_RS(char * untel);
    void CRLF();
    void Tempo(long val);
    void Octet2Hex(unsigned char number);
    void Decompile_byte(Byte un);
    
    void InterruptHandlerHigh (void);
    
    void Decompile_byte(Byte un) {
    Byte masque;
      masque = 0x80;
      while (masque > 0u )
     {
      if (un & masque)
          Put_RS(49u);  //  '1'
        else
          Put_RS(48u);  //  '0'
    
        masque =masque >>1;
         }
    }
    
    void Octet2Hex(unsigned char number)
    {
    char high,low;
      // high nibble
      high = ((number & 0xF0) >> 4) + 48; // + '0'
      if (high > '9')
        high =high + 7;
     // low nibble
      low = (number & 0x0F) + 48;          // +'0' low nibble
      if (low > '9')                       // '9'= 57u
        low += 7;                         // > '9'
      Put_RS(high);
      Put_RS(low);
      Put_RS('h');
     }
    
    
    //gestionnaire d'interruption
    //------------------------------
    // High priority interrupt vector
    #pragma code InterruptVectorHigh = 0x08
    void InterruptVectorHigh (void)
    {
      _asm
        goto InterruptHandlerHigh //jump to interrupt routine
      _endasm
    }
    
    // High priority interrupt routine
    #pragma code
    #pragma interrupt InterruptHandlerHigh
    void InterruptHandlerHigh ()
    {
      static char i ; // doit ętre statique pour conserver sa valeur entre les IT
      char C ;
    //======== SERIAL======================
    if(PIR1bits.RCIF) // si un car arrive
       {
       C =Read1USART(); // le lire => RAZ  RCIF
       if(RCSTAbits.FERR || RCSTAbits.OERR)
         {
          RCSTAbits.CREN = 0 ; RCSTAbits.CREN= 1 ;
         }
        while(Busy1USART()); // par sécurité
        if (PORTBbits.RB1==0) Write1USART(C); // echo
         if( C == BS)
            {
             if(i>0){
                 i--;  }
            }
          else
          {
          if(C != CR && i<MAX_LEN)
          {
            buffer[i++]=C ; // stockage
            }else
            {
             buffer[i]='\0'; // fin de chaîne si CR
             i=0;
             received =1;
           }
          }
        }
    } // fin de routine interrupts
    
    
    void Init_UART1(void)
    {
    // USART_BRGH_HIGH,32
    // init 38400Bd a 20Mhz
    // init 19200Bd a 10Mhz avec IT en rx
    // voir para 18.5 spec sheet DS41159B page 186
    Open1USART( USART_TX_INT_OFF &
    USART_RX_INT_ON &
    USART_ASYNCH_MODE &
    USART_EIGHT_BIT &
    USART_CONT_RX &
    USART_BRGH_HIGH,32  
    );
    INTCONbits.PEIE = 0 ; // autorisation des IT des périphériques
    INTCONbits.GIE = 0 ; // autorisation globale des IT
    }
    
    int PutStr_RS(char *s)
    {
    	int n;
    	for (n = 0; *s; n++, s++)
    	{
           	Put_RS(*s);
         	}
    	return n;
    }
    
    void Put_RS(char * untel)
    {
       	while(Busy1USART());
       	Write1USART(untel);
    }
    
    void CRLF()
    {
      Put_RS(CR);  Put_RS(LF);
      }
    
    
    void Tempo(long val)
    {
    while(val>0){val--;}
    }
    
    void main()
    {
    char a;
    unsigned char d;
    
    //OSCCON =0b01100000;
    ANSELA=0;
    TRISA = 0b00001111 ; 
    TRISAbits.TRISA4 = 0;   // led rouge
    LATA = 0x00;
    
    ANSELC=0;
    TRISCbits.TRISC6 = 0;
    TRISCbits.TRISC7 = 1;
    Led_Rouge=Allume;
    
    Init_UART1();
    
    Put_RS(CLS);   // clear  Vbray terminal Screen
    Tempo(150000L);
    Led_Rouge=Eteint;
    
    // init pour interruptions ----
      INTCONbits.GIE = 1;    // active global interrupt
      INTCONbits.GIEL=1;
      RCSTA1bits.CREN= 1 ;
      PIE1bits.RC1IE = 1;
      INTCONbits.PEIE = 1;   // autorisation des IT des périphériques
      
    buffer[0]=0;
    received=0;
    ;
    k=PutStr_RS(txt);
    
    d=0x14;
    Octet2Hex(d);
    Put_RS(TAB);
    Decompile_byte(d);CRLF();
    d=d | 1;
    Octet2Hex(d);
    Put_RS(TAB);
    Decompile_byte(d);CRLF();
    d=d ^ 1;
    Octet2Hex(d);
    Put_RS(TAB);
    Decompile_byte(d);CRLF();
    Tempo(200000L);
    CRLF();
    d=0x14;
    Octet2Hex(d);
    Put_RS(TAB);
    Decompile_byte(d);CRLF();
    d=d | 8;
    Octet2Hex(d);
    Put_RS(TAB);
    Decompile_byte(d);CRLF();
    d=d ^ 8;
    Octet2Hex(d);
    Put_RS(TAB);
    Decompile_byte(d);CRLF();
    d=d ^ 8;
    Octet2Hex(d);
    Put_RS(TAB);
    Decompile_byte(d);CRLF();
    Tempo(200000L);
    
    CRLF();
    printf("hallooo\r\n");
    // write to the USART 
    printf("Type some chars and CR to send them: ");
    
    
    while(1)
    { 
     if (received==1) // test if reception occured
     {
      j=0;  
      Led_Rouge=Allume; 
      printf("\r\nYou typed: ");    
      while (buffer[j]!=0)   
      {
        a=buffer[j]; 
        Put_RS(a);
        j++;
       // Tempo(1000L); 
      }
      received=0;
      buffer[0]=0;
     } 
    Tempo(25000L); 
    Led_Rouge=Eteint;
    }
    }
    /* results on Vbray terminal
    18F46K22 test RS232 C18
     03/07/2012 rev a
    19200bds Quartz 10Mhz 
    14h	00010100
    15h	00010101
    14h	00010100
    
    14h	00010100
    1Ch	00011100
    14h	00010100
    1Ch	00011100
    
    hallooo
    Type some chars and CR to send them: 
    
    */

  14. #44
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Je connais très bien ces opérateurs (OR XOR AND et j'en passe), mais je ne connaissais vraiment pas l'écriture "|="... Merci quand même pour ces explications.

  15. #45
    invite0e0d6f65

    Re : Problème Résistances PULL UP sur sorties PIC18F45K22

    Bonjour,

    Me revoilà avec mes questions. Bon j'ai retapé le protocole et l'ai modifié quelque peu. Malgré ces modifications la communication pêche toujours. Et vu que je n'ai pas d'oscilloscope à disposition, qui me permettrait de vérifier le contenu de mes trames, je suis quelque peu embêter... Existe t-il un logiciel ou autre pouvant faire office d'oscilloscope ?

    J'ai fait un test pour aller lire le status du capteur, mais après l'octet de commande de lecture du status, le capteur n'envoie pas de bit ACK... Sois ma trame est fausse, soit mon horloge est douteuse (fort possible mais j'ai maintenu leur système de génération d'horloge, soit la condition de départ n'est pas bonne, soit mon capteur ne veut rien savoir... Toujours est-il que ça ne fonctionne pas...

    Voici mon code pour ceux qui seraient susceptibles de trouver des erreurs :

    e2_interface.h
    Code:
    #include <p18f45k22.h>
    
    /*---------------------------Définitions--------------------------------------*/
    
    #define time 20
    #define ACK 1
    #define NACK 0
    
    #define SDA TRISBbits.TRISB1
    #define SCL TRISBbits.TRISB2
    #define SDA_IN PORTBbits.RB1
    
    
    
    
    /*-----------------------Prototypes Fonctions--------------------------------*/
    
    // Fonctions e2_interface
    
    void start(void) ;
    void stop(void) ;
    void send(unsigned char d) ;
    unsigned char read(void) ;
    unsigned char check_ack(void) ;
    void send_ack(void) ;
    void send_nack(void) ;
    void delay(unsigned int duree) ;
    unsigned char read_SDA(void) ;
    
    
    // Fonctions Lecture Status et Acquisition Mesure
    
    unsigned char read_status(void) ;
    unsigned int mesure(void) ;

    e2_interface.c

    Code:
    #include "e2_interface.h"
    
    
    /*-----------------------Déclarations des variables---------------------------*/
    
    unsigned char co2_low, co2_high = 0 ;
    unsigned int co2 ;
    unsigned char error = 0x00 ;
    
    
    
    
    /*-----------------------Fonctions E2_interface-------------------------------*/
    
    void start(void)
    {
    	SDA = 1 ;
    	SCL = 1 ;
    	delay(30 * time) ;
    	SDA = 0 ;
    	delay(30 * time) ;
    }
    
    
    void stop(void)
    {
    	SCL = 0 ;
    	delay(20 * time) ;
    	SDA = 0 ;
    	delay(20 * time) ;
    	SCL = 1 ;
    	delay(20 * time) ;
    	SDA = 1 ;
    	delay(20 * time) ;
    }
    
    
    void send(unsigned char d)
    {
    	unsigned char i = 0 ;
    
    	for(i=8; i>0; i--)
    		{
    			SCL = 0 ;
    			delay(10 * time) ;
    
    			if((d& 0x80)!= 0) SDA = 1 ;
    			else SDA = 0 ;
    
    			delay(20 * time) ;
    			SCL = 1 ;
    			d <<= 1 ;
    			delay(30 * time) ;
    			SCL = 0 ;
    		}
    
    	SDA = 1 ;
    
    }
    
    
    unsigned char read(void)
    {
    	unsigned char d = 0 ;
    	unsigned char x = 0X80 ;
    
    	for(x = 0x80 ; x > 0; x >>= 1)
    		{
    			SCL = 0 ;
    			delay(30 * time) ;
    			SCL = 1 ;
    			delay(15 * time) ;
    
    			if (read_SDA()) d |= x ;
    
    			delay(15 * time) ;
    			SCL = 0 ;
    		}
    
    	return d ;
    
    }
    
    
    unsigned char check_ack(void)
    {
    	unsigned char input = 0 ;
    
    	delay(30 * time) ;
    	SCL = 1 ;
    	delay(15 * time) ;
    	input = read_SDA() ;
    	delay(15 * time) ;
    
    	if (input == 1) return NACK ;
    	else return ACK ;
    }
    
    
    void send_ack(void)
    {
    	SCL = 0 ;
    	delay(15 * time) ;
    	SDA = 0 ;
    	delay(15 * time) ;
    	SCL = 1 ;
    	delay(30 * time) ;
    	SCL = 0 ;
    	SDA = 1 ;
    }
    
    
    void send_nack(void)
    {
    	SCL = 0 ;
    	delay(15 * time) ;
    	SDA = 1 ;
    	delay(15 * time) ;
    	SCL = 1 ;
    	delay(30 * time) ;
    	SCL = 0 ;
    }
    
    
    void delay(unsigned int duree)
    {
    	while (duree != 0)
    		{
    			duree = duree - 1 ;
    		}
    }
    
    
    unsigned char read_SDA(void)
    {
    	if (SDA_IN == 1) return 1 ;
    	else return 0 ;
    }
    
    
    
    /*-----------------Fonctions Permettant Lecture Status et Lecture Mesure Co2-----------------------*/
    
    
    unsigned char read_status(void)
    {
    	unsigned char status ;
    	unsigned char checksum = 0 ;
    
    	start() ;
    	send(0x71) ; //demande du status
    
    	if (check_ack() == 1)
    	{
    		status = read() ;
    		send_ack() ;
    		checksum = read() ;
    		send_nack() ;
    		stop() ;
    
    		if(((status + 0x71) % 256) == checksum) return status ;
    		else
    		{
    			error = 0x04 ;
    			return 0xFF ; 	// erreur
    		}
    	}
    	else error = 0x01 ;
    }
    
    
    unsigned int mesure(void)
    {
    
    	unsigned char checksum = 0 ;
    
    	start() ;
    	send(0xE1) ;
    
    	if (check_ack() == 1)
    	{
    		co2_low = read() ;
    		send_ack() ;
    		checksum = read() ;
    		send_nack() ;
    		stop() ;
    
    		if (((co2_low + 0xE1) % 256) == checksum)
    		{
    			start() ;
    			send(0xF1) ;
    
    			if(check_ack() == 1)
    			{
    				co2_high = read() ;
    				send_ack() ;
    				checksum = read() ;
    				send_nack() ;
    				stop() ;
    
    				if (((co2_high + 0xF1) % 256) == checksum)
    				{
    					 return co2 = co2_low + 256 * co2_high ;
    				}
    				else error = 0x80 ;
    			}
    			else
    			{
    				stop() ;
    			 	error = 0x20 ;
    			}
    		}
    		else error = 0x40 ;
    	}
    	else
    	{
    		stop();
    		error = 0x10 ;
    	}
    }

    Par avance merci de votre aide

Page 2 sur 2 PremièrePremière 2

Discussions similaires

  1. Problème CAN PIC18F45K22
    Par invite0e0d6f65 dans le forum Électronique
    Réponses: 4
    Dernier message: 09/06/2012, 13h59
  2. probleme 2 interruptions pull up sur 18F4550
    Par inviteac751535 dans le forum Électronique
    Réponses: 1
    Dernier message: 13/02/2012, 23h04
  3. Probleme ampli audio 37V sur les sorties HP
    Par invite4aa8396f dans le forum Électronique
    Réponses: 30
    Dernier message: 14/09/2010, 13h42
  4. resistances pull(up/down) sur circui TTL
    Par invite779ffd8e dans le forum Électronique
    Réponses: 15
    Dernier message: 29/03/2008, 14h42
  5. Pic 16f84 : Résistances de rappel au 5V ( Pull Up )
    Par invitebecbfa50 dans le forum Électronique
    Réponses: 32
    Dernier message: 28/12/2006, 22h22
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...