SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By AugustRush
#97825
Hi i'm working with the sensor MICROGMAG 3 and a development board of TI ezdsp for the TMS320F28335 DSP, and I'm trying to read each axis in the sensor but I can't, i'm sure that i am doing good the part of send the DATA to the sensor but when I wait the DTARDY signal, after that I can't receive the data I'm using the follow program

void main(void)
{

int rdata,x,y,z; // received data

asm(" EALLOW");
GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0; // habilita pullup en la salida
GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 0; // GPIO32 = GPIO32
GpioCtrlRegs.GPBDIR.bit.GPIO32 = 1; // GPIO32 = salida
asm(" EDIS");


// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.

InitSysCtrl();

// Step 2. Initalize GPIO:
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 DSP2833x_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 DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c

spi_fifo_init(); // Initialize the Spi FIFO
spi_init8bits(); // init SPI


asm(" EALLOW");

GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0; // pullUps
GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 0; // GPIO30 = GPIO30 (0) ó CANTXA (1)
GpioCtrlRegs.GPADIR.bit.GPIO30 = 1; // RESET out
GpioDataRegs.GPACLEAR.bit.GPIO30 = 1;

GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0; // pullUps
GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 0; // GPIO30 = GPIO30 (0) ó CANTXA (1)
GpioCtrlRegs.GPADIR.bit.GPIO31 = 0; // entrada DTRDY
GpioCtrlRegs.GPAQSEL2.bit.GPIO31 = 3;

asm(" EDIS");

for(;;)
{

rdata = 0;x=0;y=0;z=0;
DS2_ON();

x = readMAG(EJEX);
delay_us(100);
y = readMAG(EJEY);
delay_us(100);
z = readMAG(EJEZ);
delay_ms(200);

DS2_OFF();
}

}

void spi_init8bits()
{
SpiaRegs.SPICCR.all =0x0007; // Reset ON, risingEDGE, 8-bit char bits
SpiaRegs.SPICTL.all =0x000E; // Enable master mode, normal phase,

// disable talk , and SPI int disabled.
SpiaRegs.SPIBRR =0x0025; // Bitrate 1 Mhz (0x25)
SpiaRegs.SPICCR.all =0x0087;
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=0x204f;
SpiaRegs.SPIFFCT.all=0x0001;
}


/// EXTRA
void delay_us( volatile Uint16 Usec )
{
while( Usec-- ) // 1us loop at 150MHz CPUCLK
{
asm(" RPT #139 || NOP");
}
return;
}


void delay_ms( volatile Uint16 mseg)
{
Uint16 i;
for(i=0;i<mseg;i++)
{
delay_us(1000);
}
return;
}



void DS2_ON(void)
{
GpioDataRegs.GPBDAT.bit.GPIO32=1;
return;
}

void DS2_OFF(void)
{
GpioDataRegs.GPBDAT.bit.GPIO32=0;
return;
}

int leeEjeMAG(int eje)
{
int datos;
CS = 0; // sselect MAG03
spi_init8bits();
delay_us(10);
RESET = 1; // RESET on
delay_us(10);
RESET = 0;
delay_us(10);

// Transmit data
spi_xmit(eje);
SpiaRegs.SPISTS.bit.OVERRUN_FLAG=1; // clear bit overRUN

while(!DTARDY); // wait data

// rx data
while(SpiaRegs.SPIFFRX.bit.RXFFST !=1);// wait the data
datos = SpiaRegs.SPIRXBUF;

delay_us(10);
CS = 1;
return(datos);
}

//===========================================================================

// No more.

//===========================================================================