AnsweredAssumed Answered

How to implement an independent I2C slave performing RX/TX on ADuCM350?

Question asked by devangs3 on Sep 7, 2017
Latest reply on Sep 20, 2017 by NeoXu

I tried to implement a slave I2C device by modifying the ADuCM350 2-wire impedance example code to send data over to another microcontroller. I added this modification to the helper UART function. Is this the right way of doing it?


/* Helper function for printing results to a terminal through UART */
void print_results(char *text, int frequency, fixed32_t magnitude, fixed32_t phase, ADI_I2C_DEV_HANDLE pDevice) {
char msg[MSG_MAXLEN];
char tmp[MSG_MAXLEN];
char i2cmsg[64];
uint8_t command[16] = {0};

//uint16_t bytesRemaining=0;
char str[15];
/* Channel */
sprintf(msg, "_%s_", text);
/* Frequency */
sprintf(str, "%d", frequency);
strcat(msg, str);
strcat(msg, "_");
/* Magnitude */
sprintf_fixed32(tmp, magnitude);
strcat(msg, tmp);
strcat(msg, "_");
/* Phase */
sprintf_fixed32(tmp, phase);
strcat(msg, tmp);
/*print to terminal*/

while (command[0] != 0x30)// wait until send command is received
PERF("in receive loop.. ");
adi_I2C_SlaveReceive(pDevice, slaveID, (uint8_t *) command, 1,0);
PERF("I2C command received, sending.. ");

//send data as slave "slaveID = some address" over I2C
if(adi_I2C_SlaveTransmit(pDevice, slaveID, (uint8_t *) i2cmsg, 64))
FAIL("I2C not working");