Hello all,
I am trying to interface the TI 28335 with the Parallax Memory Stick Data Logger through SPI to record ~100, 32 bit words/second. In order to initialize the device an "E" must be sent and then will be echoed back by the DataLogger if every thing has been initialized. This process is then repeated with an "e". I have written the code below to achieve this, however it always returns a "positive" test even when no memory device is inserted, so I am convinced that it is an issue with the code. The libraries refrenced in this code are the standard libraries that come with the examples. Would someone help me out?
Thanks so much,
Tim
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
void delay_loop(void);
void spi_xmit(char a);
char spi_recieve(void);
void spi_fifo_init(void);
void spi_init(void);
void error(void);
int sync(void);
char sdata; // send data
char rdata; // received data
Uint16 ABC;
Uint16 ABS;
int count = 0;
void main(void)
{
InitSysCtrl();
InitSpiaGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
spi_fifo_init(); // Initialize the Spi FIFO
spi_init(); // init SPI
sdata = 0x0000;
ABS = sync();
}
int sync()
{
int Got_Big_E = 0; //Determines if big "E" has successfully been echoed
int Got_Little_E = 0; //Determines if little "e" has succfessfully been echoed
int LoopCount = 0; //Number of tries to read big"E"
spi_xmit('E');
spi_xmit(0x0D);
while((Got_Big_E == 0) && (LoopCount < 256))
{
while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
rdata= spi_recieve();
if(rdata == 'E')
{
Got_Big_E = 1;
ABC = 127;
}
LoopCount++;
}
if(Got_Big_E == 1)
{
spi_xmit('e');
spi_xmit(0x0D);
LoopCount = 0;
while((Got_Little_E == 0) && (LoopCount < 256))
{
while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
rdata= spi_recieve();
if(rdata == 'e')
{
Got_Little_E = 1;
ABS = 127;
}
LoopCount++;
}
}
return Got_Little_E;
}
void delay_loop()
{
long i;
for (i = 0; i < 1000000; i++) {}
}
void error(void)
{
asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}
void spi_init()
{
SpiaRegs.SPICCR.all =0x0007; // Reset on, rising edge, 8-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR =0x007F;
SpiaRegs.SPICCR.all =0x0087; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; //Switch to SPI
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; //Switch to SPI
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; //Switch to SPI
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; //Switch to SPI
}
void spi_xmit(char a)
{
Uint16 A = a;
SpiaRegs.SPITXBUF=(A%256);
}
char spi_recieve()
{
char a;
Uint16 A = SpiaRegs.SPIRXBUF;
a = (char)(A>>8);
return a;
}
void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x204f;
SpiaRegs.SPIFFCT.all=0x0;
}