I am trying to use I2C_EEPROM in the SDK 5.0.4 to write information to a digital potentiometer.
I want to write to address 0b0101100 the instruction byte 0x00 and the information 0xF8.
我用I2C_Write_Byte function but for some reason when I look on the scope it keeps sending the address byte non-stop and never anything else.
When I tried using the functions:
SEND_I2C_COMMAND(0x58);
SEND_I2C_COMMAND(0x00);
SEND_I2C_COMMAND (0 xff);
No matter what I send, it still sends the same address byte I last put in the I2C_Write_Byte function.
My questions are:
What is the most barebone way I can write three bytes (addr, instruction, data) over I2C (optional to use the SDK 5.0.4 code)?
Why is it continuously sending the address byte non-stop instead of sending the instruction/data bytes?
Had clock and data switched around. My first assumption was wrong and it cost me some time but the I2C is still sending the same address over and over.
Even when I ONLY send I2C_Write_Byte(0x22, 0x30) it still sends the address I originally hardcoded in over and over. It is just doing whatever it wants instead of the commands I am sending. I am not sure what is going on.
Hi Krixen,
If the I2C module doens't get a response from the sensor or memory and you keep on pushing for an I2C interaction the I2C will just send the address of the that is set to the I2C_TAR_REG until there is a response, before start emmiting that data that you have instructed. So the reason that you get on the analyser only the address of the module and not your data is because there is no response from the sensor on the other side when the I2C module sends the sensor's address. A bare transaction with a 2byte register address (0x22) and writing a byte (0x08) could be:
i2c_eeprom_init(I2C_SLAVE_ADDRESS, I2C_SPEED_MODE, I2C_ADDRESS_MODE, I2C_ADDRESS_SIZE);
GLOBAL_INT_DISABLE();
WAIT_UNTIL_NO_MASTER_ACTIVITY(); // Wait until no master activity
SEND_I2C_COMMAND((0x22 >> 8) & 0xFF); // Set address MSB, write access
SEND_I2C_COMMAND(0x22 & 0xFF); //Set the LSB
SEND_I2C_COMMAND(0x08 & 0xFF);
GLOBAL_INT_RESTORE();
Thanks MT_dialog