Jump to content
  • 0

ChipKit Max32 Digital IO


arjunyg

Question

I'm running the following code loosely based on a demo I found somewhere, and for some reason I can only get the pin RE3 (chipkit pin 34) to light an LED, and not RA0, RA1, RA4, or RA5 (chipkit pins 70-73). What gives?

I think my PIC32 may be broken, because I tried very carefully placing an LED on the TQFP leads and was able to see it flash on package pin 99, but not on package pin 17, 38, or 60. If I misread the datasheet...that would be good to know also.

I got the following serial output to work, which looks slightly problematic since PORTA doesn't seem to invert like PORTE does.

Hello, LATE = 8, PORTE = 8, LATEA = 51, PORTA = 51
Hello, LATE = 0, PORTE = 0, LATEA = 0, PORTA = 51
Hello, LATE = 8, PORTE = 8, LATEA = 51, PORTA = 51
Hello, LATE = 0, PORTE = 0, LATEA = 0, PORTA = 51
Hello, LATE = 8, PORTE = 8, LATEA = 51, PORTA = 51
Hello, LATE = 0, PORTE = 0, LATEA = 0, PORTA = 51
Hello, LATE = 8, PORTE = 8, LATEA = 51, PORTA = 51
Hello, LATE = 0, PORTE = 0, LATEA = 0, PORTA = 51
/* 
 * File:   main.c
 * Author: arjun
 *
 * Created on March 13, 2016, 1:27 AM
 */

// **** Include libraries here ****
// Standard libraries
#include <stdio.h>
#include <stdlib.h>

// Microchip libraries
#include <xc.h>
#include <plib.h>


// User libraries

// **** Set macros and preprocessor directives ****
#define SYS_FREQ       80000000L
#define F_PB           20000000L
#define UART_BAUD_RATE    115200
#define UART_USED          UART1

// **** Define global, module-level, or external variables here ****

// **** Declare function prototypes ****

// **** Set processor configuration ****
// Configuration Bit settings
// SYSCLK = 80 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV)
// PBCLK = 20 MHz
// Primary Osc w/PLL (XT+,HS+,EC+PLL)
#pragma config FPLLIDIV   = DIV_2     // Set the PLL input divider to 2
#pragma config FPLLMUL    = MUL_20    // Set the PLL multiplier to 20
#pragma config FPLLODIV   = DIV_1     // Don't modify the PLL output.
#pragma config FNOSC      = PRIPLL    // Set the primary oscillator to internal RC w/ PLL
#pragma config FSOSCEN    = OFF       // Disable the secondary oscillator
#pragma config IESO       = OFF       // Internal/External Switch O
#pragma config POSCMOD    = XT        // Primary Oscillator Configuration
#pragma config OSCIOFNC   = OFF       // Disable clock signal output
#pragma config FPBDIV     = DIV_4     // Set the peripheral clock to 1/4 system clock
#pragma config FCKSM      = CSECMD    // Clock Switching and Monitor Selection
#pragma config WDTPS      = PS1       // Specify the watchdog timer interval (unused)
#pragma config FWDTEN     = OFF       // Disable the watchdog timer
#pragma config ICESEL     = ICS_PGx2  // Allow for debugging with the Uno32
#pragma config PWP        = OFF       // Keep the program flash writeable
#pragma config BWP        = OFF       // Keep the boot flash writeable
#pragma config CP         = OFF       // Disable code protect


int getDelay() {
    return 0x80000;
}

int main(void)
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(SYS_FREQ);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4 the CPU frequency
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    INTEnableInterrupts();

    // Set up the UART peripheral so we can send serial data.
    UARTConfigure(UART_USED, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART_USED, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART_USED, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART_USED, F_PB, UART_BAUD_RATE);
    UARTEnable(UART_USED, UART_ENABLE | UART_TX);

    // And configure printf/scanf to use the correct UART.
    if (UART_USED == UART1) {
        __XC_UART = 1;
    }

    // Enable LED outputs 0-7 by setting TRISE register
    LATACLR = 0x33;
    TRISACLR = 0x33;
    LATASET = 0x33;
    LATECLR = 8;
    TRISECLR = 8;
    LATESET = 8;
    while (1) {
        // print serial output repeatedly
        printf("Hello, LATE = %d, PORTE = %d, LATEA = %d, PORTA = %d\n", LATE&8, PORTE&8, LATA&0x33, PORTA&0x33);
        LATAINV = 0x33;
        LATEINV = 8;
        int delay = getDelay();
        // do nothing for a lot of cycles
        int i=0;
        for(i=0;i<delay;i++);
        // shift left by 1
    }
}

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Yeah, I did use MPLAB to program the board (via a PicKit 3). I tried disconnecting the programmer and powering the board via USB, but pin 70 remains weakly powered, and the other 3 off. Is there something particular I need to set to make those pins usable as Digital IO? The Basic IO shield could not properly operate without them, so I don't understand why it would be sold as compatible if it cannot be used.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...