Jump to content
  • 0

Example project for UDB


paul2015nz

Question

6 answers to this question

Recommended Posts

Hello,

 

I am trying to help you, even if I am not sure I will be able to provide exactly what you need (I apologize if my answer suggests things that you already know).

From the beginning you must understand what your UDB device is: a microcontroller development board intended to use with a wide variety of PIC microcontrollers from Microchip.

So you can write applications for the onboard microcontroller (PIC32MX360) or any other Microchip microcontroller if you have a PIM (small board that is placed "on top" of the onboard microcontroller) with that microcontroller.

Getting started needs that you install the Microchip development tools MPLABX (also obtain the free Microchip compiler XC32).

On this hardware and softwate platform you can run and debug your applications, which are MPLABX projects

Unfortunately we don't have projects for the onboard microcontroller (PIC32MX360) and we don't know which microcontroller are you targeting. But you will find for sure examples for your microcontroller at Microchip or over the Internet.

Also, I found on the reference manual https://www.digilentinc.com/Data/Products/UDB/UDB_RM_RevE_V1.pdf:

 

The Universal Development Board is designed to be compatible with the Microchip Explorer 16 development board. The layout of the PIM connector and PICtail™ Plus bus connections are physically and electrically compatible with the Explorer 16, and many Microchip demonstration programs for the Explorer 16 will work with the UDB.

 

Or you can create a new MPLABX project, select the microcontroller you want to use and start from the beginning.

Still, I am directing you to a simple MPLABX project that blinks some LEDs on Digilent board chipKIT Pro MX7: https://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,1219&Prod=CHIPKIT-PRO-MX7 

https://www.dropbox.com/s/pw04sge2zj14tms/MX7_Blink.X.zip?dl=0. This uses the PIC32MX795F512L microcontroller and accesses ressources (LEDs) specific to chipKIT Pro MX7 board.
Link to comment
Share on other sites

Thanks Cristian,

 

I managed to setup my project and got the usart, LED, timers working. I used the explorer 16 example project and modify it to get it working.

 

The only issue I am having is getting the SPI working correctly. I have a sensor that act as a slave and master, and the SDO and SDI are tied together as recommended by the manufacturer. Sensor pinouts shown below.

 

post-714-0-55001000-1429179266_thumb.png

 

When sensor is in slave mode, I have to use 16 bit transfer to write the configuration registers. When in master, the data can be requested or continuously transmitting (default) depending on configuration. The sensor is configure to continuously transmitting as shown below and the SPI need to be configure to 32 bit transfer and SDO disabled. 

 

post-714-0-47771500-1429178600_thumb.png

 

The control line is working correctly as it just set and clear GPIO pin. 

 

The SPI setup is shown below using the plib library. 

static void init_asic_spi(bool master) {

    int rData = SPI1BUF;    //Clears receive buffer
    IFS0CLR = 0x03800000;   //Clears any existing event (rx / tx/ fault interrupt)
    SPI1STATCLR = 0x40;      //Clears overflow
    // Need to swap between master and slave to write and read from the sensor

    if (master) {
        //SPIModule Off, 16bit-mode, Master-mode, SDO1 by Module, Framed mode disabled.
        // Baud = 1.81MHz (Fpb/44 = 40/22 MHz)
        SpiChnOpen(1, SPI_CON_MSTEN | SPI_CON_MODE16 | SPI_CON_CKE | SPI_CON_ON, 22);
    } else {
        // SDO disabled, Frame disabled, CKE=1, SMP=0
        // Baud = 1.81MHz (Fpb/44 = 40/22 MHz)
        SpiChnOpen(1, SPI_CON_SLVEN | SPI_CON_MODE32 | SPI_CON_ON | SPI_CON_CKE | SPI_CON_DISSDO, 22);
        
    }
}

When reading, I use the following code. The function is called in the main loop. The problem nothing is being read back when the sensor is set to continuously transmission. The usart function works correctly when I comment getcSPI1() and set the data to 'a'. 

void test_sensor(void)
{
    uint32_t data;

    data = getcSPI1();

    if (usart_tx_callback != 0)
    {
        // transmit data back to the usart
        usart_tx_callback(data);
    }
}

I have connected RF6 (SCK1), RF7 (SDI1) and RF8 (SDO1) to the sensor. RF7 and RF8 is connected to the DATA_IO (Pin 1), RF6 is connected to SCLK (Pin 2). VSS is connected to ground and VDD to 3.3V. CONT is connected to PA0. MCLK is connected to RD1 (OC2).

 

The OC2 code is shown below and it generates a clock of 1.82Mhz and this is use for SCLK when the sensor is set to master.

#include <plib.h>

#define MAX_DUTY               21

void init_pwm_clock(void)
{
    // Setup the PWM output
    // This generate a 1.82 MHz clock based on the 80 MHz system clock
    // This uses OC2 which on the PIC32MX RD1 pin.

    // init OC2 module
    OpenOC2( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);

    // init Timer2 mode and period (PR2) (frequency of 1 / 20 kHz = (3999 + 1) / 80MHz * 1
    OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, MAX_DUTY);

    mT2SetIntPriority( 7); 	// set Timer2 Interrupt Priority
    mT2ClearIntFlag(); 		// clear interrupt flag
    mT2IntEnable( 1);		// enable timer2 interrupts
    SetDCOC2PWM(11);
}

void __ISR( _TIMER_2_VECTOR, ipl7) T2Interrupt( void)
{
    // clear interrupt flag and exit
    mT2ClearIntFlag();
} // T2 Interrupt

Control line code is shown below. Power pin is not used at the moment.

static void initialize_pins(void) {
    mPORTAClearBits( BIT_1 | BIT_0 );

    mPORTASetPinsDigitalOut( BIT_1 | BIT_0 );
}

static void set_power(bool on) {
    if (on) {
        mPORTASetBits( BIT_1 );
    } else {
        mPORTAClearBits( BIT_1 );
    }
}

static void set_asic_control(bool master) {
    if (master) {
        mPORTAClearBits( BIT_0 );
    } else {
        mPORTASetBits( BIT_0 );
    }
}

Is there anything I missed out when setting up the SPI?

 

Paul

 

post-714-0-47771500-1429178600_thumb.png

post-714-0-55001000-1429179266_thumb.png

Link to comment
Share on other sites

I have changed the SPI to use the register instead of the plib but still doesn't work.

    if (master)
    {
//        SPI1CON=0x00000460;         //460     //SPIModule Off, 16bit-mode, Master-mode, SDO1 by Module, Framed mode disabled.
        SPI1CON=0x00000460;
        TRISFCLR=BIT_8 | BIT_6; // SDO1, SCK1
    }
    else
    {
        SPI1CON=0x00001C40;
        TRISFSET=BIT_8 | BIT_7 | BIT_6; // SDO1, SDI1, SCK1
    }

    asm("NOP");
    SPI1BRG=0x16;                   //0x0C=1.846 Mhz
    SPI1STATbits.SPIROV=0;          //cleared OV bit
    SPI1CONbits.ON=1;                       //SPIModule ON
    asm("NOP");
    IFS0bits.SPI1RXIF=0;
    IEC0bits.SPI1RXIE=0;
    IPC5bits.SPI1IP=6;

And reading.

void test_sensor(void)
{
    uint32_t data;

    while(!SPI1STATbits.SPIRBF);
    data=SPI1BUF;

    if (usart_tx_callback != 0)
    {
        // transmit data back to the usart
        usart_tx_callback(data);
    }
}
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...