This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CDCM6208 CAN NOT WRITE ALL REGS FROM I2C INTERFACE, BUT CAN READ

Other Parts Discussed in Thread: CDCM6208

HI,

   I am settg the CDCM6208 from the I2C interface of a MCU. I can read the regsiters, but can not write them. The Write CMD was executed, however the value I read back was never changed.

 

  • Hello Bovey,

    could you please share a write and read sequence?

    Please also ensure, that you have 16bit register address. 

    regards,

    Julian

  • hi,

    first: the MCU is STM32F103RET6.

    //the write code:

    //u8_addr: device address;

    //u16_RegAddr: Register address;

    //u16_data: the data need be write.

    void I2C1_WriteReg_16bits(uint8_t u8_addr, uint16_t u16_RegAddr, uint16_t u16_data)
    {
    I2C_GenerateSTART(I2C1,ENABLE);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)){;}//EV5
    I2C_Send7bitAddress(I2C1,u8_addr,I2C_Direction_Transmitter);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)){;}//EV6
    I2C_SendData(I2C1,u16_RegAddr>>8 && 0xff);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)){;}//EV8_2
    I2C_SendData(I2C1,u16_RegAddr && 0xff);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)){;}//EV8_2
    I2C_SendData(I2C1,u16_data>>8 && 0xff);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)){;}//EV8_2
    I2C_SendData(I2C1,u16_data && 0xff);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)){;}//EV8_2
    I2C_GenerateSTOP(I2C1,ENABLE);
    }

    //read code

    //u8_addr: device address;

    //u16_RegAddr: Register address;

    uint16_t I2C1_ReadReg_16bits(uint8_t u8_addr,uint16_t u16_RegAddr)
    {
    uint16_t u16_Receive_data;
    I2C_GenerateSTART(I2C1,ENABLE);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)){;}//EV5
    I2C_Send7bitAddress(I2C1,u8_addr,I2C_Direction_Transmitter);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)){;}//EV6
    I2C_SendData(I2C1,u16_RegAddr>>8&&0xff);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)){;}//EV8_2
    I2C_SendData(I2C1,u16_RegAddr);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)){;}//EV8_2

    I2C_GenerateSTART(I2C1,ENABLE);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)){;}//EV5
    I2C_Send7bitAddress(I2C1,u8_addr,I2C_Direction_Receiver);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)){;}//EV6
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)){;}//EV7
    u16_Receive_data = I2C_ReceiveData(I2C1) << 8;
    I2C_AcknowledgeConfig(I2C1,DISABLE);
    while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)){;}//EV7
    u16_Receive_data = u16_Receive_data | I2C_ReceiveData(I2C1);
    while (!(I2C1->SR1 & I2C_FLAG_BTF)){;}//EV7_3

    I2C_GenerateSTOP(I2C1,ENABLE);
    I2C_AcknowledgeConfig(I2C1,ENABLE);
    return u16_Receive_data;
    }

  • hi, Julian
    i find the mistake in my code, thanks a lot!