PIC18F25K83 CAN-BUS

  • Konuyu başlatan Konuyu başlatan rms
  • Başlama tarihi Başlama tarihi

rms

Üye
Katılım
9 Ekim 2024
Mesajlar
29
Herkese merhaba,
PIC18F25K83 ile kendimi PIC mikrodenetleyiciler hakkında geliştirmek için bir proje yapıyorum. Sorunum hiçbir şekilde TX pininden data çıkışı yok. Logic analizör ile baktığımda TX pininden bir çıktı göremedim. PPS registerı ile RB2 pinini CAN0-TX, RB3 pinini (default) CAN0-RX olarak ayarlıyorum:
Kod:
CANRXPPS = 0x0B;
RB2PPS = 0x33;

aşağıdaki fonksiyon ECAN init kodu:
Kod:
void ECAN_Initialize(void) {
        
    // Enter CAN module into config mode
    CANCON = 0x00;    //REQOP<2:0>=100
    CANCONbits.REQOP = 0x04;
    while(!(CANSTATbits.OPMODE ==0x04));
    
    ECANCON = 0x00;
    
        // Initialize CAN Timing 
    if (F_ECAN_100==1)
    {
        //  100 Kbps @ 64MHz 
        BRGCON1 = 0x93; //0001 1111     //SJW=3TQ     BRP  19
        BRGCON2 = 0xB8; //1011 1000     //SEG2PHTS 1    sampled once  PS1=8TQ  PropagationT 1TQ 
        BRGCON3 = 0x05; //0000 0101     //PS2  6TQ
    }
    else if (F_ECAN_125==1)
    {
        //  125 Kbps @ 64MHz
        BRGCON1 = 0x8F; //0000 0111     //SJW=3TQ     BRP  15
        BRGCON2 = 0xB8; //1011 1000     //SEG2PHTS 1    sampled once  PS1=8TQ  PropagationT 1TQ 
        BRGCON3 = 0x05; //0000 0101     //PS2  6TQ
    }
    else if (F_ECAN_500==1)
    {
        //  500 Kbps @ 64MHz
        BRGCON1 = 0x83; //0000 0111     //SJW=3TQ     BRP  3
        BRGCON2 = 0xB8; //1011 1000     //SEG2PHTS 1    sampled once  PS1=8TQ  PropagationT 1TQ 
        BRGCON3 = 0x05; //0000 0101     //PS2  6TQ
    }
    else if (F_ECAN_1000==1)
    {
        //  1   Mbps @ 64MHz 
        BRGCON1 = 0x81; //0000 0011     //SJW=3TQ     BRP  1
        BRGCON2 = 0xB8; //1011 1000     //SEG2PHTS 1    sampled once  PS1=8TQ  PropagationT 1TQ 
        BRGCON3 = 0x05; //0000 0101     //PS2  6TQ
    }
    else
    {
        //  100 Kbps @ 64MHz 
        BRGCON1 = 0x93; //0001 1111     //SJW=3TQ     BRP  31
        BRGCON2 = 0xB8; //1010 0000     //SEG2PHTS 1    sampled once  PS1=8TQ  PropagationT 1TQ 
        BRGCON3 = 0x05; //0000 0010     //PS2  6TQ
    }
    
    // Initialize Receive Masks
    //  The first mask is used that accepts all SIDs and no EIDs
    RXM0EIDH = 0x00;    //
    RXM0EIDL = 0x00;
    RXM0SIDH = 0xFF;    // Standard ID FILTER
    RXM0SIDL = 0xE0;
    
    //  The second mask is used to ignore all SIDs and EIDs
    RXM1EIDH = 0x00;    // 0's for EID and SID
    RXM1EIDL = 0x00;
    RXM1SIDH = 0xFF;
    RXM1SIDL = 0xE0;
    
    // Enable Filters
    //  Only using two filters
    RXFCON0 = 0x03;     //Disable all
    RXFCON1 = 0x00;     //Disable all
    
    RXF0EIDH = 0x00;
    RXF0EIDL = 0x00;
    RXF0SIDH = 0x32;
    RXF0SIDL = 0xC0;

    RXF2EIDH = 0x00;
    RXF2EIDL = 0x00;
    RXF2SIDH = 0x33;
    RXF2SIDL = 0xC0;
    
    CANCON = 0x00;
    while(CANSTATbits.OPMODE==0x00);
    
    // Set Receive Mode for buffers
    RXB0CON = 0x00;
    RXB1CON = 0x00;
}

transmit fonksiyonu da aşağıdaki şekilde:
Kod:
void ECAN_Transmit(void)
{   
    TXB0EIDH = 0x00;
    TXB0EIDL = 0x00;
    
    //0x35E    0110 1011 110
    TXB0SIDH = 0x6B;
    TXB0SIDL = 0xC0;

    TXB0DLC = 0x03;
    TXB0D0 = 0xAA;
    TXB0D1 = 0xCC;
    TXB0D2 = 0x55;
    TXB0D3 = 0x00;
    TXB0D4 = 0x00;
    TXB0D5 = 0x00;
    TXB0D6 = 0x00;
    TXB0D7 = 0x00;
    
    TXB0CONbits.TXREQ = 1; //Set the buffer to transmit
}

fonksiyonları microchip mplab example projelerinden aldım.
 

Çevrimiçi üyeler

Forum istatistikleri

Konular
7,626
Mesajlar
127,263
Üyeler
3,082
Son üye
futti133

Son kaynaklar

Son profil mesajları

Python Geliştirmeye eklediğim yapay zeka sunucusu, yeni başlayanlar için roket etkisi
Bir insanın zeka seviyesinin en kolay tesbiti, sorduğu sorulardır.
yapay zeka interneti yedi bitirdi, arama motoru kullanan, forumlara yazan kaldı mı ?
Freemont2.0 herbokolog Freemont2.0 wrote on herbokolog's profile.
nick iniz yakıyor
:D
az bilgili çok meraklı
Back
Top