Forum: Mikrocontroller und Digitale Elektronik Problem SPI & SS PIC18F2580


von Siegfried S. (dieleena)


Lesenswert?

Hallo,
PIC 18F2580, MPLAP, C18
Habe folgendes Problem. Der Pic wird im Slave Modus betrieben. Der Pin 7 
(SS) wird über einen 74HC85 und einen 74HC132 gesteuert. Der Pic 
verarbeitet aber das Signal an Pin 7 nicht. Dieser verarbeitet den 
Datenstrom auch, wenn am Pin ein High Signal anliegt. Senden und 
empfangen ist in Ordnung.

Hier meine Code

//   INIT SETUP
//
// bit    76543210
PORTA = 0b00000000;        // Clear PORTA
PORTB = 0b00000000;        // Clear PORTB
PORTC = 0b00000000;        // Clear PORTC
//
// bit    76543210
LATA  = 0b00000000;        // Clear LATA
LATB  = 0b00000100;        // Clear LATB
LATC  = 0b00000000;        // Clear LATC
//
// bit    76543210
TRISA = 0b00110000;        // PORTA inputs - outputs.
TRISB = 0b00000000;        // PORTB inputs - outputs.
TRISC = 0b00011001;        // PORTC inputs - outputs.

und INIT SPI
//
//  ---->>>>  .....
INTCONbits.GIE  = 0;   //   bit 7 GIE/GIEH:   Global Interrupt Enable 
bit
                  //            When IPEN (RCON<7>) = 0:
                  //            1 = Enables all unmasked interrupts
                  //            0 = Disables all interrupts
                  //            When IPEN (RCON<7>) = 1:
                  //            1 = Enables all high priority interrupts
                  //            0 = Disables all priority interrupts
//
//  ---->>>>  .....
ADCON1    = 0x07;
//   bit 3-0   PCFG3:PCFG0: A/D Port Configuration Control bits
//        PCFG AN7 AN6 AN5 AN4 AN3 AN2 AN1 AN0 VREF+ VREF- C/R
//        011x D   D   D   D   D   D   D   D   —     —     0/0
//
//  ---->>>>  .....
INTCON2bits.RBPU = 1; //   bit 7 RBPU: PORTB Pull-up Enable bit
                  //        1 = All PORTB pull-ups are disabled
                  //        0 = PORTB pull-ups are enabled by individual 
port latch values
//
//  ---->>>>  .....
INTCON3 = 0;  //   INTCON3:   INTERRUPT CONTROL REGISTER 3
              //        disable unused unterrupts
//
//  ---->>>>  .....
PIE2 = 0x00;  //   PIE2:     PERIPHERAL INTERRUPT ENABLE REGISTER 2
              //        disable unused interrupts
//
//  ---->>>>  .....
RCONbits.IPEN = 0;  //   bit 7 IPEN: Interrupt Priority Enable bit
// 1 = Enable priority levels on interrupts
// 0 = Disable priority levels on interrupts (PIC16CXXX Compatibility 
mode)
//
//  ---->>>>  .....
TRISCbits.TRISC3 = 1; //  for SLAVE SPI the clock pin needs to be an 
input
TRISAbits.TRISA5 = 1; //  it seems both for MASTER and SLAVE this pin
                      //  needs to be an input
//
//  ---->>>>  .....
PIE1      = 0x08;     //   PIE1:     PERIPHERAL INTERRUPT ENABLE 
REGISTER 1
                      //        enable only SPI interrupts
//
//  ---->>>>  .....
SSPSTAT      = 0x00;  //   sample bit slave configuration, transmit
                      //   idle to active clock state
//
//  ---->>>>  .....
//  bit      76543210
SSPCON1 = 0b00000100; //  bit 3-0  Synchronous Serial Port Mode Select 
bits
                      //  0101 = SPI Slave mode, clock = SCK pin, SS pin
                      //        control disabled, SS can be used as I/O 
pin
                      //  0100 = SPI Slave mode, clock = SCK pin, SS pin
                      //        control enabled
                      //  0011 = SPI Master mode, clock = TMR2
                      //        output/2
                      //  0010 = SPI Master mode, clock = FOSC/64
                      //  0001 = SPI Master mode, clock = FOSC/16
//
//  ---->>>>  .....
while (PORTCbits.RC3 != SSPCON1bits.SSPEN);
           //   as section 17.3.6 at page 149 indicates, before enabling
           //   SPI slave mode
           //   program must wait for idel mode position (make sure same
           //   idel mode
//
//  ---->>>>  .....
SSPCON1bits.SSPEN = 1;  //   bit 5 SSPEN:   Synchronous Serial Port 
Enable
                        //                  bit
                        //     1 = Enables serial port and configures
                        //         SCK, SDO, SDI and SS as serial port 
pins
                        //     0 = Disables serial port and configures
                        //    these pins as I/O port Pins
//
//
//  ---->>>>  .....
RCONbits.IPEN  = 0;     //  bit 7 IPEN:   Interrupt Priority Enable bit
                  //          1 = Enable priority levels on interrupts
                  //          0 = Disable priority levels on interrupts
                  //              (PIC16CXXX Compatibility mode)
//
//  ---->>>>  .....
INTCONbits.PEIE  = 1;   //  bit 6 PEIE/GIEL:   Peripheral Interrupt 
Enable
                        //                     bit
                        //   When IPEN (RCON<7>) = 0:
                        //   1 = Enables all unmasked peripheral 
interrupts
//
//  ---->>>>  .....
INTCONbits.GIE  = 1;    //  bit 7 GIE/GIEH:   Global Interrupt Enable 
bit
                  //            When IPEN (RCON<7>) = 0:
                  //            1 = Enables all unmasked interrupts
                  //            0 = Disables all interrupts
                  //            When IPEN (RCON<7>) = 1:
                  //            1 = Enables all high priority interrupts
                  //            0 = Disables all priority interrupts


Gruß Siegfried

von Siegfried S. (dieleena)


Lesenswert?

Hallo guten morgen,
in welcher Zeile befindet sich mein Fehler ?
Gruß Siegfried

von Severino R. (severino)


Lesenswert?

Siegfried Saueressig wrote:
> Hallo guten morgen,
> in welcher Zeile befindet sich mein Fehler ?
> Gruß Siegfried

Wenn ich das wüsste!
Habe die Sache mit dem SS im Datenbuch nachgelesen und Deine 
Initialisierung scheint mir richtig.
Allerdings habe ich nicht verstanden, warum das Verhalten von SS vom CKE 
abhängen soll (Datenbuch 17.3.7)

von Siegfried S. (dieleena)


Lesenswert?

Hallo,
ich vermute, das ich die Einstellung für AD falsch gesetzt habe.
Bei diesem Projekt benötige ich keinen AD.
Gruß Siegfried

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.