AnsweredAssumed Answered

Start problem AD7195

Question asked by zz555 on Mar 27, 2017
Latest reply on May 26, 2017 by zz555

I'm trying to read ID AD7195, I can not get an answer on SPI in any way. How to learn a working chip or not?

void SPI_Write(unsigned char bytesNumber) {
   cs_reset();
   HAL_SPI_Transmit(&hspi1,(uint8_t*)&aTxBuffer, bytesNumber, 100);
   cs_set();
}

 

void SPI_Read(unsigned char bytesNumber) {
   //for (byte=0; byte<bytesNumber; byte++) {aTxBuffer[byte] = data[byte+1];}
   cs_reset();
   //HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)&aTxBuffer, (uint8_t*)&aRxBuffer, bytesNumber+1, 100);
   //data[byte] = HAL_SPI_Receive(&hspi1, (uint8_t*)&aTxBuffer[byte], bytesNumber+1, 100);
   HAL_SPI_Transmit(&hspi1,(uint8_t*)&aTxBuffer, bytesNumber, 100);
   cs_set();
   HAL_Delay(1);
   cs_reset();
   HAL_Delay(1);
   //while(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_6) == GPIO_PIN_SET);
   //HAL_SPI_Receive(&hspi1, (uint8_t*)&aTxBuffer, bytesNumber, 100);
   cs_set();
}

 

unsigned long AD7190_GetRegisterValue(unsigned char regAddr, unsigned char bytesNumber) {
   unsigned long buffer = 0x0;
   unsigned char i;

   aTxBuffer[0] = AD7195_COMM_READ | AD7195_COMM_ADDR(regAddr);
   SPI_Read(1);
   for (i=0; i<bytesNumber; i++) buffer = (buffer<<8)+aRxBuffer[i];
   return (buffer);
}

 

void AD7195_Reset(void) {
   aTxBuffer[0] = 0x01;
   aTxBuffer[1] = 0xFF;
   aTxBuffer[2] = 0xFF;
   aTxBuffer[3] = 0xFF;
   aTxBuffer[4] = 0xFF;
   aTxBuffer[5] = 0xFF;
   aTxBuffer[6] = 0xF5;
   SPI_Write(7);
}

 

unsigned char AD7195_Init(void) {
   unsigned char regVal;

   AD7195_Reset();
   regVal = AD7190_GetRegisterValue(AD7195_REG_ID, 1);
   if (regVal == ID_AD7195) return 1; else return 0;
}

Outcomes