SPI Accelerometer

OP #1172785
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 |
             SPI_FIXED_CS_0);

    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 |
            (4*SPI_SCK_DIV_FACTOR));

    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
number

  // 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
  }
  else
  {
    AT91C_BASE_SPI->SPI_TDR = (value_for_cs << 16) | character; // CS#
|Character
  }

  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
rxbyte=SPI_Read();




any help is appreciated

Reply

A question of your own? This thread is over 19 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.