Forum: Mikrocontroller und Digitale Elektronik STM3210c +Adis16209


von Benjamin P. (thecook)


Lesenswert?

Hallo zusammen,
ich versuche seit Tagen diesen Neigungssensor zum laufen zu bringen.

Initialisierung:

  SPI1_GPIO_Pin_NSS = GPIO_Pin_4;
  SPI1_GPIO_Pin_SCK = GPIO_Pin_5;
  SPI1_GPIO_Pin_MISO = GPIO_Pin_6;
  SPI1_GPIO_Pin_MOSI = GPIO_Pin_7;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1 | 
RCC_APB2Periph_AFIO, ENABLE);

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Pin = SPI1_GPIO_Pin_SCK;
  GPIO_Init(GPIOA,  &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = SPI1_GPIO_Pin_MOSI;
  GPIO_Init(GPIOA,  &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = SPI1_GPIO_Pin_MISO;
  GPIO_Init(GPIOA,  &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = SPI1_GPIO_Pin_NSS;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA,  &GPIO_InitStructure);

     SPI_I2S_DeInit(SPI1);

  SPI1_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI1_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI1_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI1_InitStructure.SPI_CPOL = SPI_CPOL_High;
  SPI1_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  SPI1_InitStructure.SPI_NSS = SPI_NSS_Hard;
  SPI1_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  SPI1_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI1_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI1, &SPI1_InitStructure);

  SPI_Cmd(SPI1, ENABLE);

Daten abfragen:
int8_t SPI1_ReadData(uint16_t register)
{
  int8_t tmp=0;

  if(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE)==SET)
  {
    tmp=SPI_I2S_ReceiveData(SPI1);
  }

  SPI_I2S_SendData(SPI1,register);
  while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET);
  tmp=SPI_I2S_ReceiveData(SPI1);

  SPI_I2S_SendData(SPI1,0xFF);
  while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET);
  tmp=SPI_I2S_ReceiveData(SPI1);

  return tmp;
}

SPI1_ReadData wird wird in der main.cs in der while-Schleife aufgerufen 
mit den Wert 0x1000 und danach 5ms delay.

Die Funktion bleibt immer hier 
"while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET);" hängen.

Vielen Dank für eure Hilfe

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.