• AVR Freaks

Hot!SPI hangs polling SPI1STATbits.SPIRBF PIC32MZ

Author
platorre
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2007/09/01 00:03:06
  • Location: 0
  • Status: offline
2019/03/17 18:43:36 (permalink)
0

SPI hangs polling SPI1STATbits.SPIRBF PIC32MZ

Hi all,
Having an issue with the pic32MZ SPI. It hangs when I try to poll the SPI1STATbits.SPIRBF bit. Everything works fine (I get CLK pulses and the HW responds with the correct values from the 23S08 IC) if I comment out the offending line. Also the value in data is always 0xFF (not reading anything).
Code below (mostly from DS):
...init IO
    SDI1R=0b0111; //set pin c14 as MISO1
    RPD2R=0b0101; //set pin D2 as MOSI1
.... init module
    SPI1BRG=0x4;   //10 MHZ clk     
    SPI1STATCLR=0x40;   //clr SPIROV
    SPI1CON=0x8220;//8 bit mode master
... read SPI
  for (i = 0; i < 2; i++)//READ 23S08 INPUTS
        {
            SS = 0;
            j = i * 2 + 0X41;
            SPI1BUF = j;
            while (!SPI1STATbits.SPITBE);
            SPI1BUF = 0x09;
            while (!SPI1STATbits.SPITBE);
            SPI1BUF = 0x00;
            while (!SPI1STATbits.SPIRBF);// HANGS HERE!
            data = SPI1BUF;
            SS = 1;
        }
kinda stumped as this is simple stuff... looked at the errata as these pics seem to have a lot of them (found that out the hard way with I2C). Didn't find anything relevant.
Thanks for your ideas!
Pablo
#1

6 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: SPI hangs polling SPI1STATbits.SPIRBF PIC32MZ 2019/03/17 18:57:29 (permalink)
    0
    Which precise PIC part are you using?
    Which pin is your SCLK?
     

    Nearly there...
    #2
    platorre
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2007/09/01 00:03:06
    • Location: 0
    • Status: offline
    Re: SPI hangs polling SPI1STATbits.SPIRBF PIC32MZ 2019/03/18 11:18:39 (permalink)
    0
    Hi,
    Thanks for the reply. I'm using a PIC32MZ2048EFM064. the clock is on RD1/SCK1. this works BTW. i can see the Clks on a LA.
    See attached:
    Thanks for your time and help!
    Pablo

    Attached Image(s)

    #3
    oldhickory
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2017/05/14 12:59:29
    • Location: 0
    • Status: offline
    Re: SPI hangs polling SPI1STATbits.SPIRBF PIC32MZ 2019/03/18 21:12:53 (permalink)
    0
    Is the SOSC disabled in your pragma bits?
    #4
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: SPI hangs polling SPI1STATbits.SPIRBF PIC32MZ 2019/03/18 21:15:29 (permalink)
    0
    oldhickory
    Is the SOSC disabled in your pragma bits?

    Isn't that on RC13 and RC14 in this PIC?
     

    Nearly there...
    #5
    marcc70
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2018/12/03 06:23:00
    • Location: 0
    • Status: offline
    Re: SPI hangs polling SPI1STATbits.SPIRBF PIC32MZ 2019/03/18 23:54:18 (permalink)
    0
    Did you set your SDI and SDO in the right way? (see picture below for example)
    Also to keep up in mind is that SCK is not pps.
    CS or SS is just a output pin by the master.
     
    Also you need to setup the SPI*CONbits in the begin of your code.
     
    * can be 1,2,3,4
     
     Edit:
     
    Below is a example of the CONbits for the SPI, this example is from Aidanmocke.
    It works fine in my code.
     
    First I make sure to setup my SDO/SDI/CS pins and then run the SPI init.
     And as I said, SCK is confirmed and not pps.
     
    Hope this works out.
     
    Cheers,
    Marc
     
    post edited by marcc70 - 2019/03/18 23:59:54

    Attached Image(s)

    #6
    oldhickory
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2017/05/14 12:59:29
    • Location: 0
    • Status: offline
    Re: SPI hangs polling SPI1STATbits.SPIRBF PIC32MZ 2019/03/19 19:53:59 (permalink)
    0
    qhb
    oldhickory
    Is the SOSC disabled in your pragma bits?

    Isn't that on RC13 and RC14 in this PIC?


    I was thinking for the MISO pin.  I agree though probably would not effect that bit poll.
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5