Part Number: AM6442
Other Parts Discussed in Thread: SYSCONFIG
Hi all,
is there an example for using the MCU+ SDK I2C driver in SLAVE mode? I could not find anything in the SDK, it looks like they are all MASTER mode examples.
Thanks,
--Gunter
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.
Hi Gunter,
Yes, you are correct. In MCU+ SDK, there is no I2C slave examples, but the I2C driver does support slave mode (no slave polling mode support though).
In mcu_plus_sdk_am64x_08_01_00_36\source\drivers\i2c\v0\i2c_v0.c, there is I2C_defaultTransaction which defines the default I2C mode as master mode. You should be able to change the .masterMode from "true" to "false". You may have to make a few changes in the example to make it works for slave mode.
Best regards,
Ming
Hi Ming,
Thanks. I went ahead and tried setting up an I2C slave example. Essentially there are two modified example codes that I am using on the AM64xx Starterkit
[1] R5F0-0: I2C read example reading on I2C0 with slave address 0x50 (i validated this working correctly with slave address 0x51 to read the EEPROM, it works)
[2] R5F1-0: I2C slave write example writing on I2C2 a value back to the master, it has slave address 0x50
[3] On the AM64xx SK, the I2C0 and I2C2 are connected with wires, so the R5F1-0 I2C2 should appear as a slave on the Master I2C0 bus
But the observation is that the I2C2 slave code is pending on the transaction complete semaphore and never completes, i.e. gets a post on that semaphore. It seems the I2C2 slave is not seeing the I2C0 Master transaction.
As a sanity check here is the code on the I2C2 Slave side
The I2C2 Slave has a modified sysconfig to configure the pins and I2C2 port.
#define I2C_SLAVE_ADDR (0x50U)
#define I2C_WRITE_LEN (1U)
static void i2c_slave_write_error_handler(uint16_t sample, int32_t status);
void i2c_slave_write_main(void *arg0)
{
uint16_t sample;
int32_t status;
uint8_t txBuffer[I2C_WRITE_LEN];
I2C_Handle i2cHandle;
I2C_Transaction i2cTransaction;
Drivers_open();
Board_driversOpen();
i2cHandle = gI2cHandle[CONFIG_I2C2];
DebugP_log("[I2C SLAVE] Write data from slave to master ... !!!\r\n");
/* Set default transaction parameters */
I2C_Transaction_init(&i2cTransaction);
/* Override with required transaction parameters */
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = I2C_WRITE_LEN;
i2cTransaction.slaveAddress = I2C_SLAVE_ADDR;
i2cTransaction.masterMode = FALSE;
txBuffer[0] = 0xAA;
/* Read 20 samples and log them */
for(sample = 0; sample < 20; sample++)
{
status = I2C_transfer(i2cHandle, &i2cTransaction);
if(status == I2C_STS_SUCCESS)
{
DebugP_log("[I2C SLAVE] Sample written to master %u: %u\r\n", sample, txBuffer[0]);
}
On the I2C0 Master side, the code is this
#define I2C_READ_SLAVE_ADDR (0x50U)
#define I2C_READ_LEN (1U)
static void i2c_read_error_handler(uint16_t sample, int32_t status);
void i2c_read_main(void *arg0)
{
uint16_t sample;
int32_t status;
uint8_t rxBuffer[I2C_READ_LEN];
I2C_Handle i2cHandle;
I2C_Transaction i2cTransaction;
Drivers_open();
Board_driversOpen();
i2cHandle = gI2cHandle[CONFIG_I2C0];
DebugP_log("[I2C] Read data ... !!!\r\n");
/* Set default transaction parameters */
I2C_Transaction_init(&i2cTransaction);
/* Override with required transaction parameters */
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = I2C_READ_LEN;
i2cTransaction.slaveAddress = I2C_READ_SLAVE_ADDR;
/* Read 20 samples and log them */
for(sample = 0; sample < 20; sample++)
{
status = I2C_transfer(i2cHandle, &i2cTransaction);
if(status == I2C_STS_SUCCESS)
{
DebugP_log("[I2C] Sample %u: %u\r\n", sample, rxBuffer[0]);
}
Could you are someone from the apps team review this, to see if anything is missing?
Thanks,
--Gunter