• AVR Freaks

AnsweredHot!Yet Another Oscillator Question

Author
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
2020/07/15 20:34:51 (permalink)
0

Yet Another Oscillator Question

24FJ128GB202.  I am looking to implement an SPI interface at 125kHz.  I tried to configure this through MCC to no avail by simply setting the baud rate in the module interface (bug?  missing something?  Idk).  Digging through the manual I see that there is a variety of configurable stuff pertaining to DOZE settings, DOZEN...looking for help getting SPI SCL to run at something, anything other than FRC = 8 MHz.  Right now after playing with dozens of settings the only thing that it is following is FRC.  Toggling MCLKEN doesn't seem to affect anything even though I have a processor clock relational divisor set in DOZE with DOZEN = TRUE.  Maybe that is the wrong approach.  If so what am I missing here?  Would like to run the core at 32MHz, usb at FS USB = 48MHz, and SPI = 125kHz.  Running out of things I can think of to look for.

Attached Image(s)

#1
ric
Super Member
  • Total Posts : 27977
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 20:48:18 (permalink)
0
Why are you looking in the system module?
Surely the SPI clock speed is set in the SPI module.
 

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
Aussie Susan
Super Member
  • Total Posts : 3735
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 20:52:21 (permalink)
0
Can you please show us the code that is generated for the oscillator and also for the SPI module.
From your description I'm not sure exactly what is working and what is not (e.g. when you write to the SSPxBUF do you get a signal on the SCK and SDO pins) so you have best show us the CONFIG settings and the PPS settings as well.
Susan
(Edit: I took so long to write my response that I had not seen Ric's)
#3
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 20:53:30 (permalink)
0
That's what I thought too.  Help me out here...what am I missing?  I notice there is not a register setting tab for this in MCC so I am off on a goose chase for something relevant in the manual.  And I am not winning the chase.

Attached Image(s)

#4
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 20:57:27 (permalink)
0
void CLOCK_Initialize(void)
{
    // CPDIV 1:1; PLLEN enabled; RCDIV FRC/1; DOZE 1:32; DOZEN enabled; ROI disabled;
    CLKDIV = 0x5820;
    // STOR disabled; STORPOL Interrupt when STOR is 1; STSIDL disabled; STLPOL Interrupt when STLOCK is 1; STLOCK disabled; STSRC SOSC; STEN disabled; TUN Center frequency;
    OSCTUN = 0x00;
    // ROEN disabled; ROSWEN disabled; ROSEL FOSC; ROOUT disabled; ROSIDL disabled; ROSLP disabled;
    REFOCONL = 0x00;
    // RODIV 0;
    REFOCONH = 0x00;
    // ROTRIM 0;
    REFOTRIML = 0x00;
    // ADC1MD enabled; T3MD enabled; T4MD enabled; T1MD enabled; U2MD enabled; T2MD enabled; U1MD enabled; SPI2MD enabled; SPI1MD enabled; T5MD enabled; I2C1MD enabled;
    PMD1 = 0x00;
    // OC5MD enabled; IC6MD enabled; OC6MD enabled; IC5MD enabled; IC4MD enabled; IC3MD enabled; OC1MD enabled; IC2MD enabled; OC2MD enabled; IC1MD enabled; OC3MD enabled; OC4MD enabled;
    PMD2 = 0x00;
    // DSMMD enabled; U3MD enabled; RTCCMD enabled; CMPMD enabled; CRCMD enabled; I2C2MD enabled;
    PMD3 = 0x00;
    // U4MD enabled; UPWMMD enabled; USB1MD enabled; CTMUMD enabled; REFOMD enabled; HLVDMD enabled;
    PMD4 = 0x00;
    // SPI3MD enabled;
    PMD6 = 0x00;
    // DMA1MD enabled; DMA0MD enabled;
    PMD7 = 0x00;
    // CRYMD enabled;
    PMD8 = 0x00;
    // CF no clock failure; NOSC FRCPLL; SOSCEN disabled; POSCEN disabled; CLKLOCK unlocked; OSWEN Switch is Complete; IOLOCK not-active;
    __builtin_write_OSCCONH((uint8_t) (0x01));
    __builtin_write_OSCCONL((uint8_t) (0x01));
    // Wait for Clock switch to occur
    while (OSCCONbits.OSWEN != 0);
    while (OSCCONbits.LOCK != 1);
}

#5
ric
Super Member
  • Total Posts : 27977
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 20:58:33 (permalink) ☼ Best Answerby IBrokeIt 2020/07/16 16:47:38
0
Shouldn't there be a call for SPI initialise?
Something has to write to the SPI1BRGL register to set the baud rate.
 

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
ric
Super Member
  • Total Posts : 27977
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 21:01:39 (permalink)
0
All that code is setting the system clock, not the SPI clock.
 

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!
#7
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 21:17:13 (permalink)
0
I get that.  I was hoping that by using CPU peripheral division from what I was reading in the manual that I could get net effect that I was looking for then came to the line of questioning...wait, why should I have to set the SPI using the equivalent of a peripheral low power mode?  Didn't seem like right answer so to the forum again.  Looking through this I see that the pre-generated code is regulating the SPI transfer mode but no default baud initialize was generated as you suggested.  It's just not there nor are the register settings or descriptions in MCC module.  So I am now looking at appendix page 48 TABLE 4-11: SPI1 REGISTER MAP as that was the only hit I got and staring at SPI1BRG<12:0> like ummm...throw me a bone here manual...
#8
ric
Super Member
  • Total Posts : 27977
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 21:25:36 (permalink)
5 (1)
IBrokeIt
...throw me a bone here manual...

Maybe at the start of the SPI chapter.

This data sheet summarizes the features ofthe PIC24FJ128GB204 family of devices.It is not intended to be a comprehensivereference source. To complement theinformation in this data sheet, refer tothe “dsPIC33/PIC24 Family ReferenceManual”, “Serial Peripheral Interface(SPI) with Audio Codec Support”(DS70005136) which is available from theMicrochip web site (www.microchip.com)


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
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 22:17:03 (permalink)
0
Yikes.  This is a little too much for me.  So to recap this adventure, I generated a stock function library through MCC for SPI, USB, and WINC.  USB worked.  WINC to be verified.  SPI does not work due to lack of generated initialization.  I question why on forum and am referred to a configuration entity I never could have guessed existed as a casual user.  Entity does not have descriptors in product documentation pass 1.  Directed to addendum for initialization routine and description (I missed the additional 64 pages of documentation redirect...granted).  Incorporated SPI initialization routine from addendum.  Interrupt routine appears to adjust time base but not jive with generated WINC code.  Interrupt routine also interferes with USB connectivity.  This will take quantities of time to figure out.
 
I'd like to change the direction I'm going if possible.  Can someone help me generate an SPI routine purely through the MCC "canned" device interface that works with generated interfaces for USB and WINC?  From the ground up.  Where did I fail using canned mechanisms?  I'm kind of on two sides of a fence.  One, folks do not utilize MCC canned functionality and prefer MLA.  On the other, assimilating multiple MLA examples and forming around individual devices is tedious at best.  Not sure if this is worth the time invested for the outcome...
#10
dan1138
Super Member
  • Total Posts : 3719
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/15 22:42:51 (permalink) ☄ Helpfulby IBrokeIt 2020/07/16 16:47:20
5 (1)
IBrokeIt
...throw me a bone here manual...

Attached is an MCC project I just created with MPLABX v5.40.
 
System clock and SPI clock configured as you requested.
 
I have no clue if this code is correct but builds with XC16.
 
Debug is your job.
post edited by dan1138 - 2020/07/15 22:45:28
#11
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/16 12:58:53 (permalink)
0
Dan, thanks a ton for posting that.  So immediately I notice differences between our builds.  I don't have a generated SPI1.c or .h.  I see yours is in 5.35 from the headers.  Mine is in 5.2.  So that could be one variable contributing to this.  Would you be so kind as to walk me through how you generated your SPI routine with MCC (I'd like to verify repeatability of my situation)?  I am assuming you selected a peripheral of SPI1, configured pins in pin manager for this peripheral, then configured the peripheral itself?  Do you have any more configuration options for SPI1 than I do in the below?  I'm trying to figure out what I missed.  Either I missed something or I am going to have a <facepalm> moment when I go to read software update & corrections document and find "v 5.4 fixed..."
 
 
post edited by IBrokeIt - 2020/07/16 12:59:58

Attached Image(s)

#12
dan1138
Super Member
  • Total Posts : 3719
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/16 14:54:01 (permalink)
5 (1)
IBrokeIt
... Either I missed something or I am going to have a <facepalm> moment when I go to read software update & corrections document and find "v 5.4 fixed..."


I am using MPLABX v5.40 with the most up to date version of MCC (v3.95.0) so I would expect if you are using previous versions there will be differences.
 
My configuration screen look like:

 
Yours seems different.
post edited by dan1138 - 2020/07/16 14:57:31

Attached Image(s)

#13
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/16 15:12:29 (permalink)
0
BINGO!  Thank you!  So I am not nuts (in this case).  You do in fact have a whole configuration tab in your SPI1 that is not available to me apparently in 5.2.  I am also running plugin 3.95.0 so it can't likely be that.  I tried creating new test projects a couple times over and cannot reproduce what you demonstrated above with v5.2.  I am going to try to update to 5.4 now to see if I observe the same as you posted...little nervous though because in reading through other posts 5.4 seems to have some other known bugs, but most look like they shouldn't affect my hardware.
#14
mpgmike
Super Member
  • Total Posts : 448
  • Reward points : 0
  • Joined: 2014/01/23 17:27:06
  • Location: NJ
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/16 16:17:52 (permalink)
0
Maybe try 5.35 which has a good track record.

I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
#15
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/16 16:25:24 (permalink)
4 (1)
Alrighty.  I just installed 5.4 and came to a realization after the fact.  There are two SPI libraries.  I grabbed the first one which is a foundation services library not knowing there should be any difference between this and anything else.  There is a second option which I did not install.  Versioning does not matter, selecting the second option yields consistent results with configuration entities across platforms.  Library differences are evident in retrospect between your and my posts Dan.
 
Fudge.  Oh well.  Won't make that mistake again.  Maybe.  Now on to break something else.
#16
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/16 17:41:28 (permalink)
0
Well, back with a follow up follow up.  Under "device resources" it appears that the device SPI library and foundation services library can't be selected and compiled concurrently.  This is unfortunate as the ATWINC1500 library apparently relies on the foundation services library to operate.  So it appears my options are to either configure SPI or not configure SPI and use WINC with MCC canned functionality.  Can someone confirm this is the case for me?  Dan, if you have your test project you made for me on hand and can independently verify that would rock.
 
If that is the case I think this MCC muffin needs to be put back in the oven cuz it's still soggy.
#17
dan1138
Super Member
  • Total Posts : 3719
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/16 18:59:42 (permalink)
5 (1)
I have no clue if any of this MCC stuff is correct but it builds.
 
You are on your own to get the WINC1500 module debugged.
post edited by dan1138 - 2020/07/17 16:07:21

Attached Image(s)

#18
IBrokeIt
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2019/08/13 12:07:00
  • Location: 0
  • Status: offline
Re: Yet Another Oscillator Question 2020/07/16 19:09:07 (permalink)
0
Working through it.  Thanks.  I see you have the default device SPI library running standalone.  I think these are designed to be mutually exclusive now after researching more.  I think the fundamentals library is meant to be like a built in MC system library for other MC devices like the WINC.  The thing that threw me off is the fact that the SPI clock is running ridiculously fast by default using this.  However, I think the SPI clock is meant to assume the quickest throughput by default the FRC can throw at it as 1:1.  At least with the chip I am using (which is the only one I have tested).  By default the FRC can only ever operate at or under the recommended transfer frequency of this board.  In any case, this may well not be a bug but rather a design aspect that was over my head until I test and observe.
 
I did get my answer from this post though pertaining to arbitrary SPI configuration from folks so thank you all.  I just broke in to a little more than I understood up front with multiple configuration libraries (there is quite a bit going on here in terms of differences and configuration assumptions between the two from what I can tell) but fuzziness with peripheral is clearing up.  I think.
#19
Jump to:
© 2020 APG vNext Commercial Version 4.5