I am trying to communicate with I2C communication a PCB with a TMS570LS0714 with an arduino. The arduino is the slave and my PCB is the master.
I wrote a function to write into the slave (arduino):
void write_slave(int address, int buffer){
/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, address);
/* Configure Data count */
/* Note: Optional - It is done in Init, unless user want to change */
//i2cSetCount(i2cREG1, DATA_COUNT_I2C);
/* Set mode as Master */
i2cSetMode(i2cREG1, I2C_MASTER);
/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);
/* Transmit Start Condition */
i2cSetStart(i2cREG1);
/* Tranmit DATA_COUNT number of data in Polling mode */
i2cSend(i2cREG1, DATA_COUNT_I2C, buffer>>24);
i2cSend(i2cREG1, DATA_COUNT_I2C, buffer>>16);
i2cSend(i2cREG1, DATA_COUNT_I2C, buffer>>8);
i2cSend(i2cREG1, DATA_COUNT_I2C, buffer);
/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true);
/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);
/* Clear the Stop condition */
i2cClearSCD(i2cREG1);
}
Where:
//PINOUT I2C
#define SLAVE_WRITE_ADDR 0xA0
#define SLAVE_READ_ADDR 0xA1
#define DATA_COUNT_I2C 8
And the code in arduino is just to send data into a Labviw interface:
#include <Wire.h>
uint8_t data;
int nByte = 0;
byte lectura[4];
unsigned long valor = 0;
void setup()
{
Wire.begin(0x50); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while (Wire.available() > 0){ // loop through all but the last
data = Wire.read(); // receive byte as a character
lectura[nByte]=data;
nByte++;
if(nByte % 4 == 0){
nByte = 0;
valor = (unsigned long)lectura[3] + ((unsigned long)lectura[2]<<8) + ((unsigned long)lectura[1]<<16) + ((unsigned long)lectura[0]<<24);
Serial.println(valor);
}
}
}
When I call the function "write_slave" the code jump into a i2c.c function with an infinite loop. Why is this happening? It does not find the slave (arduino)?

