Shop OBEX P1 Docs P2 Docs Learn Events
get data from l3g4200d by used arm micro(at91sam7x) — Parallax Forums

get data from l3g4200d by used arm micro(at91sam7x)

mohammadesmailimohammadesmaili Posts: 8
edited 2012-05-15 09:48 in Accessories
i have tried to get data from l3g4200d with using arm micro(at91sam7x256) by spi protocol .but i could not yet.is anyone can help me?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2012-05-14 15:54
    What are your problems? How do you have it hooked up and what code are you using? Details please.
  • mohammadesmailimohammadesmaili Posts: 8
    edited 2012-05-15 06:18
    i can write data to sensor but i cant read.can you give me a sample code or library that i can used for my code .
    # 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<<18);
    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<<18);
    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;



    }
    }
  • mohammadesmailimohammadesmaili Posts: 8
    edited 2012-05-15 09:48
    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 up.
Sign In or Register to comment.