Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SPI setup
26-04-2012, 11:08 AM, (This post was last modified: 26-04-2012, 11:22 AM by KiloOne.)
#11
RE: SPI setup
bjoenp,

As the others have confirmed, I am using the correct SPI registers for the PIC32MX440F256H which is used on both the OTG and MICRO of which I have both.

For those that don't know, the MICRO is less than 1/2 the size than the OTG and has more PIC pins available but less power options.

For future reference if someone ever needs this, here is the code (extract portions as needed or do it your own way) that sets the PIC32MX440F256H up to use the SPI with CPHA=1 and CPOL=1:
Code:
void getTemps(byte ibb) {
                            //SPI_init();        //actually this is done in void setup
                            //NHDsetCursor(0, 0);
                            //sprintf(buff, "%8X",  SPI2BRG );  
                            //NHDprintf(buff);
                            NHDsetCursor(1, 0);
                            NHDprintf("adr ");
    Din = addbase | ibb;
                            sprintf(buff, "%3X", Din);
                            NHDprintf(buff);
    setPEC(Din);                    // set PEC of board address
                            NHDsetCursor(1, 10);
                            NHDprintf(" + PEC ");
                            sprintf(buff, "%3X", PEC);
                            NHDprintf(buff);
                    

    SPI2CONCLR = 0x8000;                    // turn off SPI mode before changing an SPI register!!!!!!!!!!!
                                                        //NHDsetCursor(0, 0);
                            //sprintf(buff, "%8X",  SPI2CON );  
                            //NHDprintf(buff);
                            //SPI2CONSET = 0x80000000;        // FRMPOL framed SPI bit(31) to 1=ON , hex of 2^31
                            //SPI2CONSET = 0x40000000;        // FRMPOL frame sync pulse dir bit(30) to 1=slave mode , hex of 2^30
                            //SPI2CONSET = 0x20000000;        // FRMPOL frame polarity bit(29) to 1=active high , hex of 2^29
                            //SPI2CONSET = 0x200;                // set phase bit(9) to 1, hex of 2^9
                            
                            
    SPI2CONCLR = 0x100;                // clock edge bit(8) to 0                             
    SPI2CONCLR = 0x40;                // clock polarity bit(6) to 0
                            //SPI2CONSET = 0x100;                // clock edge bit(8) to 1                             
    SPI2CONSET = 0x40;                // clock polarity bit(6) to 1

    SPI2CONSET = 0x8000;                    // turn SPI mode back ON after changing an SPI register!!!!!!!!!!!
                            
                            NHDsetCursor(0, 10);
                            sprintf(buff, "%8X",  SPI2CON );  
                            NHDprintf(buff);
    pinMode(39, OUTPUT);            // PIC pin RF0 is pin 39 in digitalw.c
    digitalWrite(39, LOW);            // set CSBI low
                                    // can't change pinmodes on 37 and 38 confirms SPI mode active!!!!! next 4 lines have no affect if in
                                    //pinMode(37, OUTPUT);            // PIC pin MOSI RG8 is pin 37 in digitalw.c
                                    //digitalWrite(37, LOW);            //
                                    //pinMode(38, OUTPUT);            // PIC pin MISO RG7 is pin 38 in digitalw.c
                                    //digitalWrite(38, LOW);            //
                            //SPI_write(Din);                 // send board address
                            //SPI_write(PEC);                 // send PEC of board address
                            //SPI_write(0x30);                // send start temp conversion command
                            //SPI_write(0x50);                // send PEC of temp command
                            //digitalWrite(39, HIGH);            // set CSBI back HIGH
                            //Delayms(1000);
                            //digitalWrite(39, LOW);            // set CSBI low
    SPI_write(Din);                 // send board address
    SPI_write(PEC);                 // send PEC of board address
    SPI_write(0x0E);                // send request temp command
    SPI_write(0xEA);                // send PEC of temp command
    for (i = 0; i < 5; i ++){            // get temp reg 0-4
        TMPR[i] = SPI_read();    
        packet[i] = TMPR[i];        
    }
    PEC = SPI_read();                // get PEC of data packet
    setPECpacket(5);                // set PECpacket for the 5 bytes in packet[]
    pinMode(39, OUTPUT);            // PIC pin RF0 is pin 39 in digitalw.c
    digitalWrite(39, HIGH);            // set CSBI back HIGH
                            for (i = 0; i < 5; i ++) {
                                NHDsetCursor(2, 4*i);
                                sprintf(buff, "%3X", TMPR[i]);
                                NHDprintf(buff);
                            }
                            NHDsetCursor(3, 0);
                            NHDprintf("PECpacket ");
                            sprintf(buff, "%3X", PECpacket);
                            NHDprintf(buff);
                            Delayms(5500);
                            NHDclear();
                            Delayms(150);
}

And, yes I am pretty sure that the datastream getting to the 6803 is correct now so the answer could still be that it is not listening, I am working on that.

Two, One its all the same, m and k would work here Shy

Thanks m for input.

John,

I have been doing Windows File Explorer text searches inside all files in my Pinguino32X.2 directory with as broad a reach as 'SPI'. The SD card routines are definitely valuable in showing how to use SPI directly without SPI.c but I am still pretty sure I have the SPI setup correctly now and need to find out why 6803 does not respond when I think it should.

Now that I am pretty sure that I am screaming at the door in the correct language, I have put in a query with the chips parents (LT) to see why I am being ignored. I will report back.

Dale

And a delayed KiloTwo/second half Big Grin
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
26-04-2012, 11:43 AM,
#12
RE: SPI setup
Get one of these http://www.saleae.com/logic
They are fantastic - you can see exactly what is happening on the SPI bus.
Reply
26-04-2012, 12:09 PM,
#13
RE: SPI setup
Hi RL,

Actually I've got a ZeroPlus 16032 logic analyzer that I've been using in this post to show what has been happening.

Thanks,
Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
26-04-2012, 01:29 PM, (This post was last modified: 26-04-2012, 01:54 PM by pingotg.)
#14
RE: SPI setup
Hi Dale,

Looks like you're making progress.

I think SPI2CON bit MSSEN would let you use SS2* automatically to control the chip select for your device if you wire it to CON5-3 (aka D10 aka #SS).

John

(26-04-2012, 09:49 AM)bjoernp Wrote: mf01: True. Total confusion... funny!
So does SPI2 work then?

The header of the retrobsd project simply defines both SPI: http://retrobsd.googlecode.com/svn-histo.../pic32mx.h
On a quick search I found this confusion reflected only here: http://www.microchip.com/forums/m617739.aspx - lone question unanswered.
And indeed, the datacheat(!) on page 61 says so: SPI1 is based on 5800, SPI2 on 5A00 and in footnote 2:
SPI2 Module is not present on PIC32MX420FXXXX/440FXXXX devices.
Ya, whatever! xD

pingotg:
Then they at least screwed up their datasheet in that place. I still find it irritating, that this has not been fixed yet...
We know SPI2 works because the SD/MMC card uses it.

It looks like they made a typo yes. Maybe you've made such errors in your career?

Did you report it to Microchip? (*)

John

(*) I have done
Reply
26-04-2012, 02:43 PM,
#15
RE: SPI setup
pingotg:
Quote:It looks like they made a typo yes. Maybe you've made such errors in your career?

Now, what should I possibly answer to that? Dodgy
Anwer is: No, never ever. The mere possibility of me doing a mistake: not even conceivable! Angel
Big Grin

Quote:Did you report it to Microchip? (*)

John

(*) I have done

Now look at that! Good lad. We're all very proud of you now.
But wait, here's another place you might consider to have a look at: http://wiki.pinguino.cc/index.php/SPI
Reply
26-04-2012, 02:46 PM,
#16
RE: SPI setup
What's the point of you posting that URL?

John
Reply
26-04-2012, 05:14 PM,
#17
RE: SPI setup
My point was: Docs on that topic are missing in the wiki here, not so much on microchip.com.

But what was the point in asking me such silly questions? I was just having a little laugh for microchip, who obviously are a little confused by this little quirk in their specs themselves. Did that hurt you or anyone somehow? And I was not comparing myself to anyone in any way, but you did that. So what was your point in doing that, I wonder.
Don't care, let's not get on that road too far.

And you telling microchip about it was the best thing to do, I really mean it. I had thought about it myself, but then wasn't sure about the issue.
That's all on that. @kiloOne, please take over from here. Smile
Reply
26-04-2012, 06:06 PM,
#18
RE: SPI setup
John,

I tried using MSSEN when I was investigating Framing (which I am now pretty sure I do not want). I think that it is a framing bit but I can't be sure of that since I can't set the value to 1. I think this means that this Pic does not support it but I can't tell for sure since I can't find any reference to it on the PIC32MX440F256H datasheet.

I see that the SS pin goes low automatically in Slave mode but I don't think I want Slave mode because I think the Slave has to provide the clock.

It looks more and more like my kludge is the normal way to deal with SS in master mode if the slave wants it to go low.

Dale

I hope you guys, ummmm, well Smile
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
26-04-2012, 06:22 PM, (This post was last modified: 26-04-2012, 06:33 PM by pingotg.)
#19
RE: SPI setup
(26-04-2012, 05:14 PM)bjoernp Wrote: My point was: Docs on that topic are missing in the wiki here, not so much on microchip.com.

But what was the point in asking me such silly questions? I was just having a little laugh for microchip, who obviously are a little confused by this little quirk in their specs themselves. Did that hurt you or anyone somehow? And I was not comparing myself to anyone in any way, but you did that. So what was your point in doing that, I wonder.
Don't care, let's not get on that road too far.

And you telling microchip about it was the best thing to do, I really mean it. I had thought about it myself, but then wasn't sure about the issue.
That's all on that. @kiloOne, please take over from here. Smile
Thing is, I'm providing help to various people here and to Microchip and elsewhere. It would be much more useful if you provided help rather than wasting my time by pointing me at a wiki page that turned out to be empty when I went to it. If you've the time to waste like that why not instead write the page? Or at least don't waste my time.

John

(26-04-2012, 06:06 PM)KiloOne Wrote: John,

I tried using MSSEN when I was investigating Framing (which I am now pretty sure I do not want). I think that it is a framing bit but I can't be sure of that since I can't set the value to 1. I think this means that this Pic does not support it but I can't tell for sure since I can't find any reference to it on the PIC32MX440F256H datasheet.

I see that the SS pin goes low automatically in Slave mode but I don't think I want Slave mode because I think the Slave has to provide the clock.

It looks more and more like my kludge is the normal way to deal with SS in master mode if the slave wants it to go low.

Dale

I hope you guys, ummmm, well Smile
I agree you don't want slave mode!

I found MSSEN in the datasheet so am puzzled that you didn't. They're searchable PDFs (well, a few may not be but this one is).

Aha - maybe you didn't notice that (as with many) the device-specific datasheet (latest looks to be 61143H) refers you to the PIC32 Family Reference Manual.

In that (a multi-PDF manual) it's in #23 (dedicated to SPI). Looks to be ref. 61106G but you can easily find it from the page for the chip which I think is http://www.microchip.com/wwwproducts/Dev...e=en534168

MSSEN is detailed under Master Mode Operation but as I say I just searched for MSSEN to find its uses.

John
Reply
26-04-2012, 08:10 PM, (This post was last modified: 26-04-2012, 08:16 PM by KiloOne.)
#20
RE: SPI setup
Hi John,

I am sure you did not notice that I have been using Sec 23 #61106G since post #1 as my bible but Note #1 on page 23-8 just points me back to the device specific datasheet DS61143H which is the one that I think the note on page 23-8 points me to to see if MSSEN is available on the PIC32MX440F256H. My search for MSSEN in DS61143H came up empty.

So I think Microchip may have pointed me to a dead-end in determining if MSSEN is usable on the PIC32MX440F256H.

Did I screw-up?

In any case I can't set the bit to 1 to test it for some reason.

From my reading up on SPI interface I have come to the conclusion that it is a pretty loose standard.

Thanks,
Dale

Aha, note 2 on 23-8 says MSSEN is not part of Framing, darn why can't I set it? It is the fix for a kludge!!!
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)