SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By mohammadesmaili
#144587
I would connect a l3g4200d to a arm(at91sam7x256) using SPI connection.
But i dont find in what do I have to send to the sensor to receive true data.
So i think i just don't send the write data to my sensors .the sample code i have used peresent at bellow
# include <AT91SAM7X256.H>
int main(void)
{
int i;
float a;
AT91C_BASE_WDTC->WDTC_WDMR=AT91C_WDTC_WDDIS;
AT91C_BASE_RSTC->RSTC_RMR=0xA5000001;
//----------------------------------------------------SPEED UP-----------------------------
AT91C_BASE_CKGR->CKGR_MOR=0xF01;
AT91C_BASE_CKGR->CKGR_PLLR=0x2903FFC;
AT91C_BASE_PMC->PMC_MCKR=0x3;
AT91C_BASE_PMC->PMC_SCER=0x1;
//------------------------------------------------------------------------------------
AT91C_BASE_PMC->PMC_PCER=(1<<AT91C_ID_PIOA);
AT91C_BASE_PMC->PMC_PCER=(1<<AT91C_ID_SPI0);
//------------------------------------------------------------------------Enable Multiplexing on PIO Controller A-------------------------------------
AT91C_BASE_PIOA->PIO_PDR=(1<<12|1<<13|1<<14|1<<15|1<<16|1<<17|1<<1 8);
AT91C_BASE_PIOA->PIO_MDER=(1<<12|1<<13|1<<14|1<<15|1<<16|1<<17|1<< 18);
AT91C_BASE_PIOA->PIO_ASR=(1<<12|1<<13|1<<14|1<<15|1<<16|1<<17|1<<1 8);
AT91C_BASE_PIOA->PIO_PPUER=(1<<12|1<<13|1<<14|1<<15|1<<16|1<<17|1< <18);
//-----------------------------------------------------------------------configure spi register---------------------------------------------------------------
AT91C_BASE_SPI0->SPI_MR=0x0F000001;
AT91C_BASE_SPI0->SPI_CSR[0]=0x0F0FFF81;
//------------------------------------------------------------------------enable spi-----------------------------------
AT91C_BASE_SPI0->SPI_CR=0x1;
//-----------------------------------------------------------------------configure sensors registers(CTRl_ReG1 to CTRL_REG5)------------------------------------------------------------------
while(!(AT91C_BASE_SPI0->SPI_SR&0x2));
AT91C_BASE_SPI0->SPI_TDR=0x0F80;
AT91C_BASE_SPI0->SPI_TDR=0x1E80;
while(!(AT91C_BASE_SPI0->SPI_SR&0x2));
AT91C_BASE_SPI0->SPI_TDR=0x0084;
while(!(AT91C_BASE_SPI0->SPI_SR&0x2));
AT91C_BASE_SPI0->SPI_TDR=0x0088;
while(!(AT91C_BASE_SPI0->SPI_SR&0x2));
AT91C_BASE_SPI0->SPI_TDR=0x008C;
while(!(AT91C_BASE_SPI0->SPI_SR&0x2));
AT91C_BASE_SPI0->SPI_TDR=0x0090;
while(1)
{

//------------------------------------------------------------reading data from sensor register----------------------------------------
while(!(AT91C_BASE_SPI0->SPI_SR&0x2));
AT91C_BASE_SPI0->SPI_TDR=0x3D;
while(!(AT91C_BASE_SPI0->SPI_SR&0x1));
a=AT91C_BASE_SPI0->SPI_RDR&0xFFFF;



}
}
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]