This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Dear TI Team,
I am using the F28377S-LaunchPad XL with a simple SPI device. I need to send 16 bits at a time to set a value in a potentiometer. I started working with the example spi_loopack_cpu1 in ControlSuite to keep everything simple.
I checked the SCK output (GPIO 18 pin 76) with an oscilloscope and had 16 distinct peaks at ~3.2-3.3V. I tried a few examples with sdata = 1, then = 3, then = 8 and everything looked fine. But when I used a value of 43690 (binary: 1010101010101010), the SPISIMOA (GPIO16 pin 36) had the following output:
As a result, I start losing values. It seems to be able to handle 3 or 4 cycles up/down but any more and it drops to 1.8V.
Can you please advise what steps I can do to correct this?
Many thanks...
Source code that was used (no changes to library files) below:
#include "F28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
// __interrupt void ISRTimer2(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
int CSPin = 14; // needed for external device
void main(void)
{
GPIO_SetupPinMux(CSPin, GPIO_MUX_CPU1, 0);
GPIO_SetupPinOptions(CSPin, GPIO_OUTPUT, GPIO_PUSHPULL);
GPIO_WritePin(CSPin, 1); // note circuit diagram 0V = light on; 3.3V light off
Uint16 sdata; // send data
Uint32 counter;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_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 F2837xS_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 F2837xS_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 F2837xS_DefaultIsr.c.
// This function is found in F2837xS_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 = 0;
counter = 0;
for(;;)
{
counter++;
if (counter > 500000)
{counter = 0;}
if (counter == 10000)
{GPIO_WritePin(CSPin, 1);} // CS line high - get ready to TX / load data register
if (counter == 400000)
{GPIO_WritePin(CSPin, 0);} // CS line low - get ready to receive data
// Transmit data
if (counter == 500000) // simple delay
{
spi_xmit(sdata); // stop in debug mode and change sdata to 43690
}
} // for loop
} // main
// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:
void spi_init()
{
SpiaRegs.SPICCR.all =0x000F; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR.all =0x0063;
SpiaRegs.SPICCR.all =0x009F; // 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.
//===========================================================================
Hi Thomas,
Do you think it would be worthwhile to try to the high-speed pins (GPIO 58,59,60,61), but not in high-speed mode?
Yes, that's a good option to try.
If so, is there anything else that I would need to change other than F2837xS_Spi.c? Can you please confirm the changes below?
SPI pin you are choosing need mux option 15. Hence you need to set the appropriate fields in GPBGMUX2/GPBMUX2 to value 0x3.
Following is code for mux setting -
GpioCtrlRegs.GPBGMUX2.bit.GPIO58 = 3; // Configure GPIO58 as SPISIMOA
GpioCtrlRegs.GPBGMUX2.bit.GPIO59 = 3; // Configure GPIO59 as SPISOMIA
GpioCtrlRegs.GPBGMUX2.bit.GPIO60 = 3; // Configure GPIO60 as SPICLKA
GpioCtrlRegs.GPBGMUX2.bit.GPIO61 = 3; // Configure GPIO61 as SPISTEA
GpioCtrlRegs.GPBMUX2.bit.GPIO58 = 3; // Configure GPIO58 as SPISIMOA
GpioCtrlRegs.GPBMUX2.bit.GPIO59 = 3; // Configure GPIO59 as SPISOMIA
GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 3; // Configure GPIO60 as SPICLKA
GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 3; // Configure GPIO61 as SPISTEA
Regards,
Vivek Singh
Hi Vivek / TI Community,
Unfortunately, this was an error on my part. The SPI A configuration works fine for all values.
For anyone using MCP41XXX SPI digital potentiometer, you need to add the following line to the spi_init function:
SpiaRegs.SPICTL.bit.CLK_PHASE = 1;
to properly align the clock and data signals.
Apologies for the confusion and thank you once again for your support.
TB