• AVR Freaks

Hot!PIC24 SPI (slave) buffer always reads 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 15:23:32 (permalink)
0

PIC24 SPI (slave) buffer always reads 255(0xffff)

Hi All,
I'm working on a project that requires SPI communication (one way) from an Arduino Uno(Master) to a PIC24F16KA301(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?
 
Let me know.
 
Thanks
#1

9 Replies Related Threads

    ric
    Super Member
    • Total Posts : 27076
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC24 SPI (slave) buffer always reads 255(0xffff) 2020/02/21 14:21:25 (permalink)
    5 (1)
    enoc22
    pin 16 -> pin 11 (MOSI)

    Wrong pin.
    Pin#16 on the PIC is "SDO".
    MOSI is short for "Master Out Slave In". You should have connected to SDI on the PIC. i.e. pin#17.
     
    It would have been much more considerate to have quoted the pin names rather than just pin numbers, then I wouldn't have had to go find a PIC24F16KA301 datasheet just to help you.
     

    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!
    #2
    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 reads 255(0xffff) 2020/02/21 15:21:30 (permalink)
    0
    Hi Ric,
    Sorry about that, I'll try and get more info before posting next time.
     
    I switched the MOSI line from the arduino (pin 11) to SDI1 (pin 17) on the PIC.
    After doing that the SPI1STATbits.SPIRBF is never set to 1 (in my mind telling me that the PIC isn't filling the SPI buffer).
     
    I wonder why it would set when it connected to SDO1, but not when connected to SDI1.
    One though i had is maybe something with the CPK and CKE settings.
     
    I tried setting up Master as PIC and Arduino as Slave and was able to get transfer (with MOSI on Ardiuno connected to SDO1) without any problems.
    Any thoughts?
     
    Thanks again for the help!
     
    Oliver
    #3
    ric
    Super Member
    • Total Posts : 27076
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC24 SPI (slave) buffer always reads 255(0xffff) 2020/02/21 17:49:47 (permalink)
    0
    enoc22
    I switched the MOSI line from the arduino (pin 11) to SDI1 (pin 17) on the PIC.
    After doing that the SPI1STATbits.SPIRBF is never set to 1 (in my mind telling me that the PIC isn't filling the SPI buffer).

    You must have accidentally changed something else.
    The connections to SDI and SDO should have no bearing on SPIRBF getting set.
    It's only SS (CS) and SCLK that matter.
     

    One though i had is maybe something with the CPK and CKE settings.

    An incorrect setting there could give you unreliable data, but would NOT stop SPIRBF getting set.
     

    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!
    #4
    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 reads 255(0xffff) 2020/02/22 00:46:49 (permalink)
    0
    I was able to get the SPIRBF to set on transmission! (one down)
    I think it had to do with the _ANSXX bits not being set correctly for digital. But that's solved.
    Next.
    I am also able to get the correct integer from the buffer but only after every 8th cycle.
    Which feels like something with a shift register or something maybe....?
    I'm soo close...
    I've attached my updated PIC code as well as my arduino code.
     
    Let me know if any of this make sense or not.
     
    Thanks for the suggestions and help!
    Oliver
    post edited by Oliver H. - 2020/02/22 00:53:32
    #5
    ric
    Super Member
    • Total Posts : 27076
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC24 SPI (slave) buffer always reads 255(0xffff) 2020/02/22 01:00:23 (permalink)
    5 (1)
        _SSEN = 0;          // SS* pin is not used by the module

    Why is SS disabled?
     

    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!
    #6
    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 reads 255(0xffff) 2020/02/22 09:46:51 (permalink)
    0
    Ooops, I had copied the SPI configuration settings from a working PIC SPI master code, forgot to change that.
    Shouldn't that make it impossible to receive on a the PIC slave? or does that make it always receiving?
    I'll switch that bit as soon as I get home later tonight and test again.
     
    Thanks
    Oliver
    #7
    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 reads 255(0xffff) 2020/02/22 21:48:50 (permalink)
    0
    Ok, I want back and re-uploaded the code to the PIC with  _SSEN = 1;
    After that the _SPIRBF flag won't set (or it just stays at 0) where before with _SSEN = 0, it would set and i would get the correct values every 8th time.
    Any ways, I appreciate all the suggestions, and if anyone else has some some insight i'm all ear. I about ready to try some alternative communications besides SPI if this continues to stump me.
     
    Thanks!
     
    Oliver
    #8
    ric
    Super Member
    • Total Posts : 27076
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC24 SPI (slave) buffer always reads 255(0xffff) 2020/02/22 23:14:20 (permalink)
    5 (1)
    Your description would imply that the SS piun is not being driven low during the transaction.
    (SSEN = off means it's always active, SSEN=ON means it needs to see a low on the SS pin.)
    Double check your master is driving that signal low during the transfer, and that it is getting to the correct PIC pin.
     
     

    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!
    #9
    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 reads 255(0xffff) 2020/02/23 21:58:59 (permalink)
    0
    I've checked and i am driving the SS pin low before sending data and i have it connected to SS1 (pin 18) on the pic. I'm kinda stumped. I though i've done everything for proper SPI but i don't know if it's a setting on the PIC or arduino that i'm missing or what.
     
    Whats really got me thrown is i can do PIC to arduino perfect, just not the other way around.
     
    Thanks
    Oliver
    post edited by Oliver H. - 2020/02/23 22:00:13
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5