Other Parts Discussed in Thread: C2000WARE
想用C2000控制ADS8355采样,却采不了,能帮忙看一下程序哪里有问题嘛
#include <syscfg/board.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define EPWM1_TIMER_TBPRD 2000U//设置周期位2000个时钟周期
#define EPWM1_CMPA 1000U//比较器的值为1000
volatile uint16_t sData,i;//发送的数据 // Send data buffer
volatile uint16_t r1Data[80];
volatile uint16_t r2Data[80];
//
// Function Prototypes
//
void initEPWM1(void);
__interrupt void SPIISR(void);
void configGPIOs(void);
void initSPIAMaster(void);
//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
//
Device_init();
//
// Disable pin locks and enable internal pull ups.
//
Device_initGPIO();
//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();
//
// Assign the interrupt service routines to ePWM interrupts
//
Interrupt_register(INT_EPWM1, &SPIISR);
configGPIOs();
//
// Configure GPIO0/1 , GPIO2/3 and GPIO4/5 as ePWM1A/1B, ePWM2A/2B and
// ePWM3A/3B pins respectively
//
Board_init();
//
// Disable sync(Freeze clock to PWM as well)
//
SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
initEPWM1();
//
// Enable sync and clock to PWM
//
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
//
// Enable ePWM interrupts
//
Interrupt_enable(INT_EPWM1);
//
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
//
EINT;
ERTM;
SPI_writeDataNonBlocking(SPIA_BASE, 0x00010400);//默认值
SPI_writeDataNonBlocking(SPIA_BASE, 0x00010500);//默认值
SPI_writeDataNonBlocking(SPIA_BASE, 0x00010D00);//默认值
SPI_writeDataNonBlocking(SPIA_BASE, 0x00011100);//默认值
SPI_writeDataNonBlocking(SPIA_BASE, 0x00012000);//默认值
SPI_writeDataNonBlocking(SPIA_BASE, 0x000124FF);
SPI_writeDataNonBlocking(SPIA_BASE, 0x00012501);//设置满量程
SPI_writeDataNonBlocking(SPIA_BASE, 0x000126FF);
SPI_writeDataNonBlocking(SPIA_BASE, 0x00012701);
SPI_writeDataNonBlocking(SPIA_BASE, 0x00012800);//设置测量范围
//
// IDLE loop. Just sit and loop forever (optional):
//
for(;;)
{
NOP;
}
}
void initSPIAMaster(void)
{
//
// Must put SPI into reset before configuring it
//
SPI_disableModule(SPIA_BASE);
//
// SPI configuration. Use a 500kHz SPICLK (可以达到50MHZ)and 16-bit word size.
//
SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0,
SPI_MODE_MASTER, 500000, 16);//DEVICE_LSPCLK_FREQ 代表50MHZ,SPI_PROT_POL0PHA0调的四种模式
SPI_setEmulationMode(SPIA_BASE, SPI_EMULATION_FREE_RUN);//设置当暂停的时候,数据还怎么传输
SPI_disableLoopback(SPIA_BASE);//跟实际通讯设备需要禁用
//
// FIFO and interrupt configuration
//
SPI_enableFIFO(SPIB_BASE);
//
// Configuration complete. Enable the module.
//
SPI_enableModule(SPIB_BASE);
SPI_enableFIFO(SPIA_BASE);//使能FIFO 口
SPI_enableModule(SPIA_BASE);//使能SPI功能
//
//
}
//
// epwm1ISR - ePWM 1 ISR
//
__interrupt void SPIISR(void)
{
//
// Update the CMPA and CMPB values
//
r1Data[i++] = SPI_readDataNonBlocking(SPIA_BASE);//第一个口收取数据
r2Data[i++] = SPI_readDataNonBlocking(SPIA_BASE);//第二个口收取数据
//
// Clear INT flag for this timer
//
EPWM_clearEventTriggerInterruptFlag(myEPWM1_BASE);//必须要
//
// Acknowledge interrupt group
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);//必须要
}
//
// initEPWM1 - Configure ePWM1
//
void initEPWM1()
{
//
// Set-up TBCLK
//
EPWM_setTimeBasePeriod(myEPWM1_BASE, EPWM1_TIMER_TBPRD);
EPWM_setPhaseShift(myEPWM1_BASE, 0U);
EPWM_setTimeBaseCounter(myEPWM1_BASE, 0U);
//
// Set Compare values
//
EPWM_setCounterCompareValue(myEPWM1_BASE,
EPWM_COUNTER_COMPARE_A,
EPWM1_CMPA);
//
// Set up counter mode
//
EPWM_setTimeBaseCounterMode(myEPWM1_BASE, EPWM_COUNTER_MODE_UP);
EPWM_disablePhaseShiftLoad(myEPWM1_BASE);
EPWM_setClockPrescaler(myEPWM1_BASE,
EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1);
//
// Set up shadowing
//
EPWM_setCounterCompareShadowLoadMode(myEPWM1_BASE,
EPWM_COUNTER_COMPARE_A,
EPWM_COMP_LOAD_ON_CNTR_ZERO);//没什么屌用,咱只用一个
//
// Set actions
//
EPWM_setActionQualifierAction(myEPWM1_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);//等于CMPA的时候又重新输出高电平
EPWM_setActionQualifierAction(myEPWM1_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);//等于0的时候开始输出低电平
//
// Interrupt where we will change the Compare Values
// Select INT on Time base counter zero event,
// Enable INT, generate INT on 3rd event
//
EPWM_setInterruptSource(myEPWM1_BASE, EPWM_INT_TBCTR_PERIOD);//时基寄存器等于1个周期的时候进行触发
EPWM_enableInterrupt(myEPWM1_BASE);//开启中断
EPWM_setInterruptEventCount(myEPWM1_BASE, 1U);//经过1次就可以触发
//
// Information this example uses to keep track of the direction the
// CMPA/CMPB values are moving, the min and max allowed values and
// a pointer to the correct ePWM registers
//
}
void configGPIOs(void)
{
//
// This test is designed for an external loopback between SPIA
// and SPIB.
// External Connections:
// -GPIO25 and GPIO17 - SPISOMI
// -GPIO24 and GPIO16 - SPISIMO
// -GPIO27 and GPIO19 - SPISTE
// -GPIO26 and GPIO18 - SPICLK
//
//
// GPIO17 is the SPISOMIA.
//
GPIO_setMasterCore(17, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_17_SPISOMIA);
GPIO_setPadConfig(17, GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(17, GPIO_QUAL_ASYNC);
//
// GPIO16 is the SPISIMOA clock pin.
//
GPIO_setMasterCore(16, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_16_SPISIMOA);
GPIO_setPadConfig(16, GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(16, GPIO_QUAL_ASYNC);
//
// GPIO19 is the SPISTEA.
//
GPIO_setMasterCore(19, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_19_SPISTEA);
GPIO_setPadConfig(19, GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(19, GPIO_QUAL_ASYNC);
//
// GPIO18 is the SPICLKA.
//
GPIO_setMasterCore(18, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_18_SPICLKA);
GPIO_setPadConfig(18, GPIO_PIN_TYPE_PULLUP);//CS
GPIO_setQualificationMode(18, GPIO_QUAL_ASYNC);
//
GPIO_setMasterCore(55, GPIO_CORE_CPU1);
GPIO_setPinConfig( GPIO_55_SPISOMIA);
GPIO_setPadConfig(55, GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(55, GPIO_QUAL_ASYNC);
}
//
// initEPWM2 - Configure ePWM2
//
// updateCompare - Function to update the frequency
//