Start problem AD7195

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;
}

Parents
  • I can not write to REG_OFFSET.
    I am writing 0x807600, later I read 0x800000 (should read 0x807600).
    I read that before you write to REG_OFFSET ADC needs to be translated into Idle mode (MD = 010) - does not work.
    What am I doing wrong?

    My code:

    // MD(000)=0 - Continuous conversion mode
    // MD(001)=2 - Single conversion mode
    // MD(010)=4 - Idle mode
    // MD(011)=6 - Power-down mode
    // MD(100)=8 - Internal zero-scale calibration
    // MD(101)=A - Internal full-scale calibration
    // MD(110)=C - System zero-scale calibration
    // MD(111)=E - System full-scale calibration

    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); // CS_0
    AD7195_SetRegisterValue(AD7195_REG_MODE, 0x440001, 2, 0); // Idle mode 0x440001 or 0x448401
    AD7195_WaitRdyGoLow();
    AD7195_SetRegisterValue(AD7195_REG_OFFSET, 0x807600, 2, 0); // write 0x807600, read 0x800000
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); // CS_1

    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); // CS_0
    AD7195_SetRegisterValue(AD7195_REG_MODE, 0x048401, 2, 0); // MD=0
    AD7195_WaitRdyGoLow();
    num = AD7195_GetRegisterValue(AD7195_REG_OFFSET, 2, 0); // resd 0x800000
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); // CS_1
    numUart(num);

Reply
  • I can not write to REG_OFFSET.
    I am writing 0x807600, later I read 0x800000 (should read 0x807600).
    I read that before you write to REG_OFFSET ADC needs to be translated into Idle mode (MD = 010) - does not work.
    What am I doing wrong?

    My code:

    // MD(000)=0 - Continuous conversion mode
    // MD(001)=2 - Single conversion mode
    // MD(010)=4 - Idle mode
    // MD(011)=6 - Power-down mode
    // MD(100)=8 - Internal zero-scale calibration
    // MD(101)=A - Internal full-scale calibration
    // MD(110)=C - System zero-scale calibration
    // MD(111)=E - System full-scale calibration

    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); // CS_0
    AD7195_SetRegisterValue(AD7195_REG_MODE, 0x440001, 2, 0); // Idle mode 0x440001 or 0x448401
    AD7195_WaitRdyGoLow();
    AD7195_SetRegisterValue(AD7195_REG_OFFSET, 0x807600, 2, 0); // write 0x807600, read 0x800000
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); // CS_1

    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); // CS_0
    AD7195_SetRegisterValue(AD7195_REG_MODE, 0x048401, 2, 0); // MD=0
    AD7195_WaitRdyGoLow();
    num = AD7195_GetRegisterValue(AD7195_REG_OFFSET, 2, 0); // resd 0x800000
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); // CS_1
    numUart(num);

Children
No Data