EmbDev.net

Forum: ARM programming with GCC/GNU tools SPI Accelerometer


von Mike J. (cobra050)


Rate this post
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 |
             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

von Edwinn S. (egwyn)


Rate this post
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.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.