Hello,
sorry to border you again, but I have a problem that block me for many days. I read all nordic questions on TWI (I2C) but did not found a solution... :(
I have implemented TWI with zephyr i do not have any problem, it works perfectly. Here below my ZEPHYR code.
If i read 0xA5 register address before write it I read 0x20, and after writing it I read 0xFD. And this is ok.
#define FRAM_I2C_ADDR 0x6D
ret = i2c_reg_write_byte(i2c_dev_name, FRAM_I2C_ADDR, 0xA5, 0xFD);
if (ret) {
printk("Error writing to sensor! error code (%d)\n", ret);
return;
} else {
printk("Scrittura ok.\n");
data[0] = 0x00;
ret = i2c_reg_read_byte(i2c_dev_name, FRAM_I2C_ADDR, 0xA5, &data[0]);
printk("Leggo il valore del registro A5, valore %d \n", data[0]);
}
But I can't have the same result with SDK17.
If I read 0xA5 register address before write it I read 0x20, and after writing it i read always 0x20. it seems that writing function does not work. Here below my code.
#define FRAM_I2C_ADDR 0x6D
#define SYS_REG 0xA5
#define SYS_REG_VALUE 0xFD
void sys_config(){
ret_code_t err_code;
uint8_t reg[2] = {SYS_REG, SYS_REG_VALUE};
m_xfer_done = false;
err_code = nrf_drv_twi_tx(&m_twi, FRAM_I2C_ADDR, reg, sizeof(reg), false);
if (err_code) {
NRF_LOG_INFO("Error (%d)\n", err_code);
return;
} else {
NRF_LOG_INFO("Success \n");
while(!m_xfer_done){}
m_xfer_done = false;
err_code = nrf_drv_twi_rx(&m_twi, FRAM_I2C_ADDR, &m_sample, sizeof(m_sample));
if(err_code) {
NRF_LOG_INFO("Error \n");
} else {
NRF_LOG_INFO("Success register A5 %d \n", m_sample);
}
}
}
Can you see something wrong in my sys_config() func?
My function on SDK17 for wrting address on i2C device it's ok? what is wrong? Why i can not write 0xA5 register as in zephyr?
I have lost a lot of time on it... Any suggerstions are welcome.
Thanks again for you support.
Best regards