SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By js_9013
#197789
I am trying to configure a SparkFun Minigen using the existing MiniGen Arduino library. However, I am using a TI MSP432 as the controller and not an Arduino.

On the face of it, this should be relatively simple as it's just a matter of configuring the TI to send the control bits to the MiniGen using their own SPI libraries. However, I am having a bear of a time figuring out why this isn't working and am quite frankly totally stuck with how to move forward.

I have included the C code below - I am using the Minigen.c and Minigen.h libraries provided on the Github page (https://github.com/sparkfun/MiniGen/blo ... iniGen.cpp) with no modifications. The only changes I have made are to the TI code, which only transmits one byte at a time. Can anyone point out what is wrong with trying to even reset the MiniGen? All I am getting is a 1 Vpp sin wave at 3 MHz.
Code: Select all
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
#include "minigen.h"

/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>

/* SPI Master Configuration Parameter */
const eUSCI_SPI_MasterConfig spiMasterConfig =
{
        EUSCI_B_SPI_CLOCKSOURCE_SMCLK,             // SMCLK Clock Source
        3000000,                                   // SMCLK = DCO = 3MHZ
        500000,                                    // SPICLK = 500khz
        EUSCI_B_SPI_MSB_FIRST,                     // MSB First
        EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT,    // Phase
        EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH, // High polarity
        EUSCI_B_SPI_3PIN                           // 3Wire SPI Mode
};

void configSpi(){
    /* Selecting P1.5 P1.6 and P1.7 in SPI mode */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
        GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
    /*  P1.5 SCLK, P1.6 SIMO */

    /* Configuring SPI in 3wire master mode */
    SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig);

    /* Enable SPI module */
    SPI_enableModule(EUSCI_B0_BASE);

    //Pin 3.0 FSYNC
    GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN0);
}

void SpiWrite(uint16_t data){
    int n = 0;

    GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_PIN0);
    for (n = 0; n <= 1; n++)
        SPI_transmitData(EUSCI_B0_BASE, (data >> (8*n)) & 0xff);
    GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN0);
}

int main(void)
{
    /* Halting WDT  */
    WDT_A_holdTimer();

    configSpi();

    minigen_reset();

    while (1) {
    };
}
By js_9013
#197837
Any help? I have measured the SPI bits and they are exactly correct compared to what the MiniGen library is supposed to expect. I am at my wit's end with this device and can't figure out why it isn't working!

Here's a quick update on the TI code:
Code: Select all
/* DriverLib Includes */
#include <minigen.h>
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
#include <stdint.h>
#include <stdbool.h>

/* SPI Master Configuration Parameter */
const eUSCI_SPI_MasterConfig spiMasterConfig =
{
        EUSCI_B_SPI_CLOCKSOURCE_SMCLK,             // SMCLK Clock Source
        3000000,                                   // SMCLK = DCO = 3MHZ
        500000,                                    // SPICLK = 500khz
        EUSCI_B_SPI_MSB_FIRST,                     // MSB First
        EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT,    // Phase
        EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, // High polarity
        EUSCI_B_SPI_3PIN                           // 3Wire SPI Mode
};

void configSpi(){
    /* Selecting P1.5 P1.6 and P1.7 in SPI mode */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
        GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
    /*  P1.5 SCLK, P1.6 SIMO */

    /* Configuring SPI in 3wire master mode */
    SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig);

    /* Enable SPI module */
    SPI_enableModule(EUSCI_B0_BASE);

    //Pin 3.0 FSYNC
    GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_PIN0);
    GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN0);
}

void SpiWrite(uint16_t data) {
    uint16_t byte2 = data & 0xff00;
    byte2 >>= 8;
    uint8_t transByte2 = (uint8_t)byte2;

    uint16_t byte1 = data & 0x00ff;
    uint8_t transByte1 = (uint8_t)byte1;

    GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_PIN0);
    SPI_transmitData(EUSCI_B0_BASE, transByte2);
    SPI_transmitData(EUSCI_B0_BASE, transByte1);
    GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN0);
}

int main(void)
{
    /* Halting WDT  */
    WDT_A_holdTimer();

    configSpi();

    minigen_reset();
    minigen_setMode(SQUARE);
    uint32_t newFreq = minigen_freqCalc(140000.0);
    minigen_adjustFreq(FREQ0, FULL, newFreq);

    while (1) {
    };
}
By paulvha
#197842
I don't know Minigen nor MSP432 but a couple of thoughts trying to help you :

1. Are you sure that your SpiWrite is executed instead of the default for Arduino ( SPIWrite())? Maybe include a Serail.println(F("here in my SpiWrite")); to show it does. The reason for asking is that minigen.cpp is also calling for configSPIPeripheral() which it is able to find, but NOT in your '.ino' (so where ?) and normally the C or C++ is case sensative.

2. If it does, looking into a number of code samplesfor TI I see that they implement an interrupt check, before write of each a byte there is a test on : while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT))); Would that make a difference in SpiWrite() ?

regards,
Paul