Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * -------------------------------------------
- * MSP432 DriverLib - v2_20_00_08
- * -------------------------------------------
- *
- * --COPYRIGHT--,BSD,BSD
- * Copyright (c) 2014, Texas Instruments Incorporated
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * --/COPYRIGHT--*/
- /*******************************************************************************
- * MSP432 DMA - eUSCI SPI Transfer Using DMA
- *
- * Description: In this code example, the MSP432 's DMA controller is used in
- * conjunction with the eUSCI_A0 SPI configuration to demonstrate how to use
- * hardware triggered DMA transfers. One DMA transfer is setup, Channel 0 is
- * for the DMA transfer. Once the transfers are setup and initialized, the
- * device is put to sleep. While sleeping, the DMA controller will automatically
- * transfer the data from the const array and out through the uESCI A0 SPI
- * module as a master. When the DMA transfer is complete, an interrupt will be
- * fired and the master will disable further interrupts
- *
- * This program runs infinitely until manually halted by the user.
- *
- * MSP432P401
- * ------------------
- * /|\| |
- * | | |
- * --|RST P1.1 (CLK) |
- * | P1.3 (MOSI)|
- * | |
- *
- * Author: Ryan Brown
- ******************************************************************************/
- /* DriverLib Includes */
- #include "driverlib.h"
- /* Standard Includes */
- #include <stdint.h>
- #include <string.h>
- #include <stdbool.h>
- /* SPI Master Configuration Parameter */
- const eUSCI_SPI_MasterConfig spiMasterConfig =
- {
- EUSCI_A_SPI_CLOCKSOURCE_SMCLK, // MCLK Clock Source
- 12000000, // MCLK = 12MHz
- 400000, // SPICLK = 400khz
- EUSCI_A_SPI_MSB_FIRST, // MSB First
- EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, // Phase
- EUSCI_SPI_CLOCKPOLARITY_INACTIVITY_LOW, // Low polarity
- EUSCI_A_SPI_3PIN // 3Wire SPI Mode
- };
- /* DMA Control Table */
- #ifdef ewarm
- #pragma data_alignment=256
- #else
- #pragma DATA_ALIGN(controlTable, 256)
- #endif
- uint8_t controlTable[256];
- /* Extern */
- extern uint8_t data_array[];
- int main(void)
- {
- /* Halting Watchdog */
- WDT_A_holdTimer();
- CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);
- /* Port 2.4 as GPIO used for CS active low */
- GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN4);
- GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4);
- /* Selecting P2.1 P2.2 and P2.3 in SPI mode */
- GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,
- GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
- /* Configuring SPI in 3wire master mode */
- SPI_initMaster(EUSCI_A1_BASE, &spiMasterConfig);
- /* Enable SPI module */
- SPI_enableModule(EUSCI_A1_BASE);
- /* Configuring DMA module */
- DMA_enableModule();
- DMA_setControlBase(controlTable);
- DMA_disableChannel(2);
- /* Assigning Channel 2 to EUSCIA0TX0 */
- DMA_assignChannel(DMA_CH2_EUSCIA1TX);
- /* Disabling channel attributes */
- DMA_disableChannelAttribute(DMA_CH2_EUSCIA1TX,
- UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST |
- UDMA_ATTR_HIGH_PRIORITY |
- UDMA_ATTR_REQMASK);
- /* Setting Control Indexes */
- DMA_setChannelControl(UDMA_PRI_SELECT | DMA_CH2_EUSCIA1TX,
- UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_NONE | UDMA_ARB_1);
- DMA_setChannelTransfer(UDMA_PRI_SELECT | DMA_CH2_EUSCIA1TX,
- UDMA_MODE_BASIC, data_array,
- (void*) MAP_SPI_getTransmitBufferAddressForDMA(EUSCI_A1_BASE), 1024);
- /* Assigning/Enabling Interrupts */
- DMA_assignInterrupt(DMA_INT1, 2);
- Interrupt_enableInterrupt(INT_DMA_INT1);
- /* Drive CS Low to indicate start of the dtransfer */
- GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4);
- /* Now that the DMA is primed and setup, enabling the channels. The EUSCI
- * hardware should take over and transfer/receive all bytes */
- DMA_enableChannel(2);
- /* Polling to see if the TX buffer is ready */
- while (!(SPI_getInterruptStatus(EUSCI_A1_BASE,EUSCI_A_SPI_TRANSMIT_INTERRUPT)));
- //PCM_gotoLPM0InterruptSafe();
- while(1);
- }
- /* Completion interrupt for eUSCIA0 TX */
- void dma_1_interrupt(void)
- {
- /* Disabling the completion interrupt and disabling the DMA channels */
- DMA_disableChannel(2);
- DMA_disableInterrupt(INT_DMA_INT1);
- /* Drive CS High to indicate end of the dtransfer */
- GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement