Dear friends,
I am writing a simple function to read a bunch of bytes from a i2c slave. I'm going to configure my TMS570 MCU as an I2C Master and want to read "len" bytes from the "reg_addres" register at the "BEE_CTRL_I2C_ADD" i2c slave. The problem is that it works only for "len" == 1. If "len" > 1 then my rpgram get stuck at while ((i2c->STR & (uint32)I2C_RX_INT) == 0U); (line 520 in HL_i2c.c).
here is my code:
int dummy_Int_read_reg (u8_t reg_address,u8_t* data_ptr, u32_t len){
int ret = 0;
u32_t i;
/*****************************************************************************/
i2cSetMode(i2cREG1,I2C_MASTER);
/*****************************************************************************/
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
i2cREG1->MDR |= I2C_REPEATMODE; //Repeat Mode
i2cSetSlaveAdd(i2cREG1, BEE_CTRL_I2C_ADD);
i2cSetStart(i2cREG1);
/***send the register address****/
I2cSendByte(i2cREG1, reg_address);
/*wait for the TX completion *****/
while (! i2cIsTxReady(i2cREG1) );
i2cSetDirection(i2cREG1, I2C_RECEIVER);
i2cREG1->MDR |= (I2C_REPEATMODE); // Repeat Mode
i2cSetStart(i2cREG1); //repeated start
/***receive the data bytes ********/
i2cReceive(i2cREG1, len, data_ptr);
i2cSetStop(i2cREG1);
return ret;
}
Does anybody have some ideas on what could be wrong here?
I am running in polling mode.
I have noticed another strange behaviour at the scope:
from time to time it happens that, even when "len" == 1, two bytes are read instead of one. Actually it seems that the 2nd accidental byte read cycle is little shorter (less SCL pulses) that the regular one.
I hope someone could help me.
Thanks a lot in advance.
Massimo