Helpful ReplyHot!Help with setting up a simple 32MX170F256B project

Author
led_flasher
Starting Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2014/10/30 09:57:31
  • Location: 0
  • Status: offline
2018/10/26 11:11:34 (permalink)
0

Help with setting up a simple 32MX170F256B project

Hi all,
This is my first PIC32 project, and as always, its a blinky led project, just to prove my knowledge of the configuration and tool chain. I am having problems with setting the configuration bits, and also setting two portB pins as outputs (RB4 and RB12). So far, I can get RB12 to light, but not flash. RB4 does not light or flash. I think the main problem is that my clock is not working. Could you take a look at my code below?
Thank you,
Phil
 
#1
davekw7x
Entropy++
  • Total Posts : 1692
  • Reward points : 0
  • Joined: 2012/01/16 12:01:07
  • Location: Left Coast, USA
  • Status: offline
Re: Help with setting up a simple 32MX170F256B project 2018/10/26 13:15:43 (permalink)
5 (1)
 
 
led_flasher
...
This is my first PIC32.
...



A couple of observations/suggestions:
  1. For new project of any kind: My very first attempts will be using internal clock.  This has two advantages:
        It removes any doubts about clock component selection, layout, etc., for my circuit
        It allows other people to evaluate my code even if their hardware is different from mine
  2. RB4 is input only. [Edit] See my later post to see how to disable the Secondary Oscillator to be able to use RB4 as an output [/Edit]
  3. What the heck is up with your delay function?.
void delay (void)
{
    int x = 65535;
    for(x = 0; x <=x; x++) // <--- Really? x <= x?
    {
        ;
    }
}

 
Regards,
 
Dave
post edited by davekw7x - 2018/10/27 07:23:02

Sometimes I just can't help myself...
#2
led_flasher
Starting Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2014/10/30 09:57:31
  • Location: 0
  • Status: offline
Re: Help with setting up a simple 32MX170F256B project 2018/10/27 00:51:29 (permalink)
0
Hi Dave,
Thanks for spotting my school boy error in the delay. RB12 led is now flashing as expected, but no flashing at RB4, I’m guessing I still have an active peripheral on RB4 instead of a plain digital output?
#3
qhb
Superb Member
  • Total Posts : 9614
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Help with setting up a simple 32MX170F256B project 2018/10/27 06:02:15 (permalink) ☄ Helpfulby Jim Nickerson 2018/10/27 06:03:27
5 (2)
led_flasher
...
but no flashing at RB4, I’m guessing I still have an active peripheral on RB4 instead of a plain digital output?

Did you see Dave's point#2 ?
 
#4
led_flasher
Starting Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2014/10/30 09:57:31
  • Location: 0
  • Status: offline
Re: Help with setting up a simple 32MX170F256B project 2018/10/27 06:26:16 (permalink)
0
Hi qhb, yes, but I issued a TRIS statement for RB4 to turn it into an output. Is RB4 not configurable as a digital output? I didn't see anything in the datasheet to indicate this.
#5
davekw7x
Entropy++
  • Total Posts : 1692
  • Reward points : 0
  • Joined: 2012/01/16 12:01:07
  • Location: Left Coast, USA
  • Status: offline
Re: Help with setting up a simple 32MX170F256B project 2018/10/27 06:42:16 (permalink)
0
led_flasher
...Is RB4 not configurable as a digital output? I didn't see anything in the datasheet to indicate this.

RB4 is shared with the secondary oscillator input SOSCI.
 
There is some ambiguity in the data sheet (I'm looking at DS60001168J):
 
Page 20: SOSCI is shown as Input.  Oscillator input pins are rarely (if ever) useful as GPIO outputs.
 
However...
 
Page 21: RB4 is shown as I/O.
 
[Edit]
Bottom line: To use RB4 as a GPIO, you must disable the Secondary Oscillator.
[/Edit]
 
 
Regards,

Dave
 
 
post edited by davekw7x - 2018/10/27 07:03:02

Sometimes I just can't help myself...
#6
led_flasher
Starting Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2014/10/30 09:57:31
  • Location: 0
  • Status: offline
Re: Help with setting up a simple 32MX170F256B project 2018/10/27 06:48:02 (permalink)
0
Thanks for that clarification Dave, much appreciated. I'll try an alternative pin on PORT B and see if I can get two led's flashing !
 
#7
davekw7x
Entropy++
  • Total Posts : 1692
  • Reward points : 0
  • Joined: 2012/01/16 12:01:07
  • Location: Left Coast, USA
  • Status: offline
Re: Help with setting up a simple 32MX170F256B project 2018/10/27 06:59:09 (permalink)
0
led_flasher
Thanks for that clarification Dave, much appreciated. I'll try an alternative pin on PORT B and see if I can get two led's flashing !
 


Sorry, my original response was not correct.  I have edited my previous post to indicate:
 
You can use RB4 as an output for this chip by disabling the Secondary Oscillato.
 
Use this
 
#pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)

 
Tested on my PIC32MX170F256B breadboard.
 
[Edit]
Leaving it on with the pragma and clearing the SOSCEN bit in OSCCON seems not to work.  The pragma to turn it off appears to be necessary.
[/Edit]
 
 
Regards,

Dave
post edited by davekw7x - 2018/10/27 07:21:25

Sometimes I just can't help myself...
#8
led_flasher
Starting Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2014/10/30 09:57:31
  • Location: 0
  • Status: offline
Re: Help with setting up a simple 32MX170F256B project 2018/10/27 07:20:06 (permalink)
0
Excellent news, I'll give this a try.
There are some very helpful contributors on this thread, thanks to both :-)
#9
Jump to:
© 2019 APG vNext Commercial Version 4.5