Forum: ARM programming with GCC/GNU tools SPI Accelerometer

Author: Mike Jones (cobra050)
Posted on:

Rate this post
0 useful
not useful
I'm trying to get the ADIS16003 to work with my AT91SAM7S256-EK

my SPI Init looks like this:

void SPI_Init(void)
  AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_SPI ) ;
    AT91F_SPI_Reset     (AT91C_BASE_SPI);
    AT91F_SPI_Enable    (AT91C_BASE_SPI);
    AT91F_SPI_CfgMode   (AT91C_BASE_SPI,
               AT91C_SPI_MSTR |
               SPI_FIX_SLCT |
             SPI_CS_DIRECT |
             SPI_MODE_FAULT_DS |
             SPI_LOCAL_LOOP_DS |

    AT91F_SPI_CfgCs     (AT91C_BASE_SPI, 0,
               SPI_SCK_IDLE_LOW |
             SPI_SCK_SAMPLE_RISING |
             SPI_CS_HIGH_AFTR_TRANS |
             SPI_16_BITS_PER_TRANS |

    AT91F_PIO_CfgPeriph( AT91C_BASE_PIOA,
    ((unsigned int) AT91C_PA13_MOSI    ) |
    ((unsigned int) AT91C_PA14_SPCK    ) |
    ((unsigned int) AT91C_PA11_NPCS0   ) |
    ((unsigned int) AT91C_PA12_MISO    ),
        0 );

AND here are my read and write functions:

int SPI_Send(char character, unsigned int cs_number, int last_xfer)
  unsigned int value_for_cs;
  value_for_cs = (~(1 << cs_number)) & 0xF; //Place a zero amonga 4 ONEs

  // Wait for transmit data register to become available
  while ( !(AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TDRE) );
  if (last_xfer)
    AT91C_BASE_SPI->SPI_TDR = (value_for_cs << 16) | character |
AT91C_SPI_LASTXFER; // CS# | Character | Last xfer
    AT91C_BASE_SPI->SPI_TDR = (value_for_cs << 16) | character; // CS#

  return 0;

int SPI_Read()
  int rxbyte;
  while ( !(AT91C_BASE_SPI->SPI_SR & AT91C_SPI_RDRF) );
  rxbyte = AT91C_BASE_SPI->SPI_RDR & 0xff;
  return rxbyte;

I do the following but get the same value for rxbyte every time

SPI_Send(4,0,0); //tells ADIS to read x-axis

any help is appreciated

Author: Edwinn Silva (egwyn)
Posted on:

Rate this post
0 useful
not useful
Hi, you can get work whit adis ??, I'm trying but with HC08, but  not to
obtain an answer of adis, your already you are able to obtain some
measurement?. please any help.


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.