小白,求帮忙看一下,我用的例程中的spi_loopback_cpu01,其中分别依次使用GPIO16-19作为SPISIMOA、SPISOMIA、***、SPISTEA,我把这思路GPIO替换成了GPIO50-53,然后没有输出,想问一下,更改gpio口,除了配置gpio还有其他需要更改吗?麻烦帮忙看一下,是我的程序哪里出现了问题了吗?
下面是我修改后的F2837xD_spi.c:
//###########################################################################
//
// FILE: F2837xD_Spi.c
//
// TITLE: F2837xD SPI Initialization & Support Functions.
//
//###########################################################################
// $TI Release: F2837xD Support Library v130 $
// $Release Date: Mon Oct 20 10:15:06 CDT 2014 $
//###########################################################################
#include "F2837xD_device.h" // F2837xD Headerfile Include File
#include "F2837xD_Examples.h" // F2837xD Examples Include File
//—————————————————————————
// Example: InitSpiGpio:
//—————————————————————————
// This function initializes GPIO pins to function as SPI pins
//
// Each GPIO pin can be configured as a GPIO pin or up to 3 different
// peripheral functional pins. By default all pins come up as GPIO
// inputs after reset.
//
// Caution:
// For each SPI peripheral
// Only one GPIO pin should be enabled for SPISOMO operation.
// Only one GPIO pin should be enabled for SPISOMI operation.
// Only one GPIO pin should be enabled for *** operation.
// Only one GPIO pin should be enabled for SPISTE operation.
// Comment out other unwanted lines.
void InitSpiGpio()
{
InitSpiaGpio();
}
void InitSpiaGpio()
{
EALLOW;
GpioCtrlRegs.GPBPUD.bit.GPIO50= 0; // Enable pull-up on GPIO16 (SPISIMOA)
GpioCtrlRegs.GPBPUD.bit.GPIO51 = 0; // Enable pull-up on GPIO17 (SPISOMIA)
GpioCtrlRegs.GPBPUD.bit.GPIO52 = 0; // Enable pull-up on GPIO18 (***)
GpioCtrlRegs.GPBPUD.bit.GPIO53 = 0; // Enable pull-up on GPIO19 (SPISTEA)
GpioCtrlRegs.GPBQSEL2.bit.GPIO50= 3; // Asynch input GPIO16 (SPISIMOA)
GpioCtrlRegs.GPBQSEL2.bit.GPIO51 = 3; // Asynch input GPIO17 (SPISOMIA)
GpioCtrlRegs.GPBQSEL2.bit.GPIO52 = 3; // Asynch input GPIO18 (***)
GpioCtrlRegs.GPBQSEL2.bit.GPIO53 = 3; // Asynch input GPIO19 (SPISTEA)
GpioCtrlRegs.GPBMUX2.bit.GPIO50 = 6; // Configure GPIO16 as SPISIMOA
GpioCtrlRegs.GPBMUX2.bit.GPIO51 = 6; // Configure GPIO17 as SPISOMIA
GpioCtrlRegs.GPBMUX2.bit.GPIO52 = 6; // Configure GPIO18 as ***
GpioCtrlRegs.GPBMUX2.bit.GPIO53 = 6; // Configure GPIO19 as SPISTEA
EDIS;
}
//===========================================================================
// End of file.
//===========================================================================
主程序里面,没有变:
//###########################################################################
// FILE: Example_2837xDSpi_FFDLB.c
// TITLE: SPI Digital Loop Back program.
//
//! \addtogroup cpu01_example_list
//! <h1>SPI Digital Loop Back (spi_loopback)</h1>
//!
//! This program uses the internal loop back test mode of the peripheral.
//! Other then boot mode pin configuration, no other hardware configuration
//! is required. Interrupts are not used.
//!
//! A stream of data is sent and then compared to the received stream.
//! The sent data looks like this: \n
//! 0000 0001 0002 0003 0004 0005 0006 0007 …. FFFE FFFF \n
//! This pattern is repeated forever.
//!
//! \b Watch \b Variables \n
//! – \b sdata – sent data
//! – \b rdata – received data
////###########################################################################
// $TI Release: F2837xD Support Library v130 $
// $Release Date: Mon Oct 20 10:15:06 CDT 2014 $
//###########################################################################
#include "F28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
// __interrupt void ISRTimer2(void);
void delay_loop(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
void error(void);
void main(void)
{
Uint16 sdata; // send data
Uint16 rdata; // received data
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
InitSysCtrl();
// 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// Setup only the GP I/O only for SPI-A functionality
// This function is found in F2837xD_Spi.c
InitSpiaGpio();
// Step 3. Clear all __interrupts and initialize PIE vector table:
// Disable CPU __interrupts DINT;
// Initialize 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 = 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();
// Step 4. Initialize the Device Peripherals:
spi_fifo_init(); // Initialize the Spi FIFO
spi_init(); // init SPI
// Step 5. User specific code:
// Interrupts are not used in this example. sdata = 0x0000; for(;;)
{ // Transmit data
spi_xmit(sdata);
// Wait until data is received
while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
// Check against sent data
rdata = SpiaRegs.SPIRXBUF;
if(rdata != sdata) error();
sdata++;
}
}
// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:
void delay_loop()
{
long i;
for (i = 0; i < 1000000; i++) {}
}
void error(void)
{
asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}
void spi_init()
{ SpiaRegs.***.all =0x000F; // Reset on, rising edge, 16-bit char bits
SpiaRegs.***.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR.all =0x007F;
SpiaRegs.***.all =0x009F; // Relinquish SPI from Reset
// SpiaRegs.***.all =0x008F; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF=a;
}
void spi_fifo_init(){
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x2044;
SpiaRegs.SPIFFCT.all=0x0;
}
//===========================================================================
// No more.
//===========================================================================
user5739360:
回复 BIN YAO1:
大神,求问个问题,SPIB怎么配置呀?弄了很久都不对,多谢了!