“线程:C2000WARE”中讨论的其它部件
我的启动板是 C2000 LaunchPad XL TMS28379D 版本:2.0
我将 GPIO58~61配置为无 FIFO 和中断的 SPIA GPIO
我可以确保 GPIO58~61能够以正确的功能运行,因为我以前将其配置为通用 GPIO 并使外部 LED 指示灯呈右闪烁
我调试示例:C2000Ware_4_00_00_00\device_support\f2837xd\examples\CPU1\SPI_loopback_interrupts 和 SPI_loopback_DMA。 他们甚至没有来自 SPICLK 的信号!!!
这是我的代码:
void SPI_Init(void)
{
//GPIO58
GpioCtrlRegs.GPBGMUX2.bit.GPIO58=3;
GpioCtrlRegs.GPBMUX2.bit.GPIO58=3;
GpioCtrlRegs.GPBDIR.bit.GPIO58=1;
GpioCtrlRegs.GPBPUD.bit.GPIO58=0;
GpioCtrlRegs.GPBODR.bit.GPIO58=1;
//GPIO59
GpioCtrlRegs.GPBGMUX2.bit.GPIO59=3;
GpioCtrlRegs.GPBMUX2.bit.GPIO59=3;
GpioCtrlRegs.GPBDIR.bit.GPIO59=0;
GpioCtrlRegs.GPBPUD.bit.GPIO59=0;
//GPIO60
GpioCtrlRegs.GPBGMUX2.bit.GPIO60=3;
GpioCtrlRegs.GPBMUX2.bit.GPIO60=3;
GpioCtrlRegs.GPBDIR.bit.GPIO60=1;
GpioCtrlRegs.GPBPUD.bit.GPIO60=0;
GpioCtrlRegs.GPBODR.bit.GPIO60=1;
//GPIO61
GpioCtrlRegs.GPBGMUX2.bit.GPIO61=3;
GpioCtrlRegs.GPBMUX2.bit.GPIO61=3;
GpioCtrlRegs.GPBDIR.bit.GPIO61=1;
GpioCtrlRegs.GPBPUD.bit.GPIO61=0;
GpioCtrlRegs.GPBODR.bit.GPIO61=1;
SpiaRegs.SPICCR.bit.SPISWRESET=0;
SpiaRegs.SPICCR.bit.CLKPOLARITY=0;
SpiaRegs.SPICCR.bit.SPICHAR=7;
SpiaRegs.SPICTL.bit.CLK_PHASE=0;
SpiaRegs.SPICTL.bit.MASTER_SLAVE=1;
SpiaRegs.SPICTL.bit.TALK=1;
SpiaRegs.SPIBRR.bit.SPI_BIT_RATE=99;
SpiaRegs.SPICCR.bit.SPISWRESET=1;
}
unsigned char SPI_WriteRead(unsigned char in)
{
SpiaRegs.SPITXBUF=in;
while(SpiaRegs.SPISTS.bit.INT_FLAG!=1);
return SpiaRegs.SPIRXBUF;
}void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
//
InitSysCtrl();
#ifdef _STANDALONE
#ifdef _FLASH
//
// Send boot command to allow the CPU2 application to begin execution
//
IPCBootCPU2(C1C2_BROM_BOOTMODE_BOOT_FROM_FLASH);
#else
//
// Send boot command to allow the CPU2 application to begin execution
//
IPCBootCPU2(C1C2_BROM_BOOTMODE_BOOT_FROM_RAM);
#endif
#endif
//
// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
//
#ifdef _FLASH
InitFlash();
#endif
//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
InitGpio(); // Skipped for this example
InitPieCtrl();
InitPieVectTable();
EALLOW;
// SCIB_GPIO18_GPIO19_Init();
// PWM_Init();
SPI_Init();
//
// TODO Add code to allow configuration of GPADIR from CPU02 using IPC
//
EDIS;
//
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
DINT;
//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xD_PieCtrl.c file.
//
// InitPieCtrl();
//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
// IER = 0x100;
IER = 0x0000;
// IFR = 0x0000;
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
//
// InitPieVectTable();
//
// Enable global Interrupts and higher priority real-time debug events:
//
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
char temp[6],i;
//
// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;)
{
DELAY_US(1000);
GpioDataRegs.GPBCLEAR.bit.GPIO61=1;
SPI_WriteRead(0x02|0x80);
for(i=0;i<6;i++)
{
temp[i]=SPI_WriteRead(0xff);
}
GpioDataRegs.GPBSET.bit.GPIO61=1;
}
}