Post Go back to editing

Unable to read from ADAU1701 via microcontroller (With Pictures)

Category: Software
Product Number: ADAU1701

Hello. I wired a DC source to a readback cell as below.

Then, I exported the files and programmed the DSP ADAU1701 via NUCLEO-F746ZG board as:

void SIGMA_WRITE_REGISTER_BLOCK(int devAddress, int address, int length, ADI_REG_TYPE *pData) {

ADI_REG_TYPE I2C_buffer[2 + length];

I2C_buffer[0] = (address & 0xFF00) >> 8; // High byte of the address

I2C_buffer[1] = (address & 0x00FF); // Low byte of the address

// Copy the data into the I2C buffer

for (int i = 0; i < length; i++) {

I2C_buffer[2 + i] = pData[i];

}

// Transmit the data via I2C

if (HAL_I2C_Master_Transmit(&hi2c2, DEVICE_ADDR_IC_1, I2C_buffer, 2 + length, HAL_MAX_DELAY) == HAL_OK) {

HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_SET);

} else {

HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_RESET);

}

}

There is no problem by programming the data via MCU. The problem is when I try to read the data back to the MCU via I2C.

I try to read as:

void SIGMA_READ_REGISTER_BYTES(int address, int length) {

ADI_REG_TYPE write_buffer[4];

write_buffer[0]=(0x0000 & 0xFF00) >> 8;

write_buffer[1]=(0x0000 & 0x00FF);

write_buffer[2]=0x00;

write_buffer[3]=0x22;

ADI_REG_TYPE read_buffer[3];

HAL_StatusTypeDef transmitStatus, receiveStatus;

transmitStatus = HAL_I2C_Master_Transmit(&hi2c2, 0x68, write_buffer, 4, HAL_MAX_DELAY);

HAL_Delay(100);

receiveStatus = HAL_I2C_Master_Receive(&hi2c2, 0x69, read_buffer, 3, HAL_MAX_DELAY);

HAL_Delay(100);

if (receiveStatus == HAL_OK) {

HAL_GPIO_WritePin(LED_2_GPIO_Port, LED_2_Pin, GPIO_PIN_SET);

} else {

Error_Handler();

}

}

I exactly write the data outputted in the sigma studio. But the slave doesnt recognizce the device.

Below is where I call read/write functions:

void default_download_IC_1() {

SIGMA_WRITE_REGISTER_BLOCK( DEVICE_ADDR_IC_1, REG_COREREGISTER_IC_1_ADDR, REG_COREREGISTER_IC_1_BYTE, R0_COREREGISTER_IC_1_Default );

SIGMA_WRITE_REGISTER_BLOCK( DEVICE_ADDR_IC_1, PROGRAM_ADDR_IC_1, PROGRAM_SIZE_IC_1, Program_Data_IC_1 );

SIGMA_WRITE_REGISTER_BLOCK( DEVICE_ADDR_IC_1, PARAM_ADDR_IC_1, PARAM_SIZE_IC_1, Param_Data_IC_1 );

SIGMA_WRITE_REGISTER_BLOCK( DEVICE_ADDR_IC_1, REG_COREREGISTER_IC_1_ADDR , R3_HWCONFIGURATION_IC_1_SIZE, R3_HWCONFIGURATION_IC_1_Default );

SIGMA_WRITE_REGISTER_BLOCK( DEVICE_ADDR_IC_1, REG_COREREGISTER_IC_1_ADDR, REG_COREREGISTER_IC_1_BYTE, R4_COREREGISTER_IC_1_Default );

ADI_REG_TYPE MODE_0_0[4] = {0x00, 0x80, 0x00, 0x00};

SIGMA_WRITE_REGISTER_BLOCK( DEVICE_ADDR_IC_1, 0x0000, 4, MODE_0_0);

SIGMA_READ_REGISTER_BYTES(0x81A, 4);

}

  • Hello berk,

    This is one of our older processors and we improved things a lot after this part. You cannot directly access the readback. You have to use the trap register. This is detailed in the datasheet and I detailed it further in this old post:

    (+) ADAU1701 Low Instruction Level Detection Readback - Q&A - SigmaDSP Processors & SigmaStudio Dev. Tool - EngineerZone

    For my quick little test program I have a DC cell feeding a readback and it is listed in the trap register text file:

    It is the first thing on the list since it was on the top left of the schematic.

    In my case I would have to write a decimal 31 into the trap register. Note in your program it is writing an 0x22 into the trap register address of 0x081A and then going back to read the result at least one sample period later.  

    Dave T

  • Thank you for your answer Dave. My program outputted: Instance 2 Signal ReadBack1_ReadBackAlg1 trap value 8 register MAC_out

    According to the output and table 27 and 28, I should be able to read from the ADAU1701 DSP as,

    void SIGMA_READ_REGISTER_BYTES(int address = 0x81A) {

    ADI_REG_TYPE write_buffer[4];

    write_buffer[0] = (address & 0xFF00) >> 8; // Byte 0: Address high byte

    write_buffer[1] = (address & 0x00FF); // Byte 1: Address low byte

    write_buffer[2] = (0x22 & 0xFF00) >> 8;

    write_buffer[3] = (0x22 & 0x00FF);

    ADI_REG_TYPE read_buffer[5];

    read_buffer[0] = (address & 0xFF00) >> 8;

    read_buffer[1] = (address & 0x00FF);

    HAL_StatusTypeDef transmitStatus, receiveStatus;

    transmitStatus = HAL_I2C_Master_Transmit(&hi2c2, 0x68, write_buffer, 4, HAL_MAX_DELAY);

    Hal_Delay(100);

    receiveStatus = HAL_I2C_Master_Receive(&hi2c2, 0x69, read_buffer, 5, HAL_MAX_DELAY);

    if (receiveStatus == HAL_OK) {

    HAL_GPIO_WritePin(LED_2_GPIO_Port, LED_2_Pin, GPIO_PIN_SET);

    } else {

    Error_Handler();

    }

    }

    but still I cannot read it. Do you see any missing points on my implementation?

  • I finally figured out the problem. The main problem relies with "Repeated start requirement". In order to fix this I changed 

    HAL_I2C_Master_Transmit(..) to HAL_I2C_Mem_Read(..)

    and the problem is somehow solved.

  • Yes, the repeated start is important in certain places so you maintain the memory address but change the command from a write to a read. You have to write to set the data address you want to read from. Then perform a repeated start to change it to a read to read from that address you set in the last write command...

    Glad you got it going!

    Dave T

  • My bad! I put the wrong line to my solution reply. In the end  HAL_I2C_Mem_Read(..) was the lifesafer eventough I dont know why :) Thank you for your time Dave! Your explanations were really helpful!