• AVR Freaks

Hot!PIC24 SPI -slave- buffer always 255/0xffff

Author
Oliver H.
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2020/02/18 22:55:26
  • Location: 0
  • Status: offline
2020/02/20 16:57:33 (permalink)
0

PIC24 SPI -slave- buffer always 255/0xffff

Hi All,
I'm working on a project that requires SPI communication -one way- from and Arduino Uno-Master- to a PIC24KA301-slave-.
I'm running into an issue where my SPI1BUF is always reading 255/0xFFFF.
I've checked the SPI signal coming out of the arduino on an osciliscope and everything looks good with the SS/SCK/MOSI signals.
 
Pin connections:
PIC -> Arduino
pin 18 -> pin 10 SS
pin 16 -> pin 11 MOSI
pin 15 -> pin 13 SCK
I have the Arduino SPI in mode 1:
Mode 1 - clock is normally low ,CPOL = 0, and the data is sampled on the transition from high to low -trailing edge-CPHA = 1

 
I'm polling the SPIRBF bit to check for a received byte in a loop and turn on a LED and then clear the bit by reading the buffer. I then check the buffer value which is always 255.
 
Any thoughts on why this might be?
 
Full code file attached.
Below is my SPI set up.

    // SPI1CON1 Register (Register 16-2)
    _DISSCK = 0; // Enable SPI clock on SCK1 pin
    _DISSDO = 0; // Enable SDO1 (MOSI) pin (pin 16)
    _MODE16 = 0; // Communication is byte-wide (8 bits)
    _CKE = 1; // Serial output data changes on
                        // transition from active to idle
    _SSEN = 1; // SS pin
    _CKP = 0; // Idle state for clock is low, active state is high
    _MSTEN = 0; // Master mode
    _SPRE = 0b110; // Secondary prescale 2:1
    _PPRE = 0b10; // Primary prescale 4:1

    // SPI1CON2 Register (Register 16-3)
    _FRMEN = 0; // Framed SPI support disabled
    _SPIBEN = 0; // Enhanced buffer disabled (legacy mode)
    _SMP = 0;

    // SPI1STAT Register (Register 16-1)
    _SPIROV = 0; // Clear overflow flag
    _SPIEN = 1; // Enable SPI module

and my main function

    configure_SPI1();

    // Configure pin 14 (RA6) as an input to be used
    // as the SS* pin
    ANSA = 0; // set all A as digital
    ANSB = 0; //
    _TRISB12 = 1;
    _TRISB13 = 1;
    _TRISB14 = 1;
    _TRISB15 = 1;
    _TRISA6 = 1; // input
    ///set all pins as inputs
    _TRISA0 = 0; // output
    _TRISA1 = 0; // output
    SPI1BUF = 0;
    int x;
    while(1){
        if(SPI1STATbits.SPIRBF){
            x=SPI1BUF;
            _LATA0 = 1;
            _LATA1 = 1;
            __delay_ms(100);
            _LATA0 = 0;
            _LATA1 = 0;
            if(x==255){
                _LATA0 = 0;
                _LATA1 = 1;
                __delay_ms(100); 
            }
        }else{
            _LATA0 = 0;
            _LATA1 = 0;
        }
    }
    return 1;
}

 
 
Let me know. 
Thanks
Oliver
 
#1

2 Replies Related Threads

    Oliver H.
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2020/02/18 22:55:26
    • Location: 0
    • Status: offline
    Re: PIC24 SPI -slave- buffer always 255/0xffff 2020/02/21 10:47:43 (permalink)
    0
    Sorry for the double post. New to the forum.
    #2
    ric
    Super Member
    • Total Posts : 27716
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC24 SPI -slave- buffer always 255/0xffff 2020/02/21 14:23:35 (permalink)
    0
    I've posted an answer in your other topic at https://www.microchip.com/forums/m1129158.aspx
    n.b. 255 is not 0xFFFF, it's just 0xFF
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5