Hi,
We are using da14580 IC for Bluetooth development. We connect the same on an external microcontroller using I2C. Da14580 working as a master it receives 250 bytes from the mobile application and sends them to an external microcontroller.The controller process that data and generate 250-byte data in response. The controller sends the data back to da14580 but da14580 receive only 64 bytes .The code for I2C init, read and write are attached
#define I2C_BUFFER_LEN 250
#define I2C0 5
#define SCC_I2C_TIMEOUT 0xffff
#define SCC_INIT_VALUE 0x00
#define SCC_I2C_BUS_WRITE_ARRAY_INDEX 0x00
void BLE_I2C_Init(uint16_t dev_address, uint8_t speed, uint8_t address_mode)
{
SetBits16(CLK_PER_REG, I2C_ENABLE, 1); // enable clock for I2C
SetWord16(I2C_ENABLE_REG, 0x0); // Disable the I2C controller
SetWord16(I2C_CON_REG, I2C_MASTER_MODE | I2C_SLAVE_DISABLE |I2C_RESTART_EN); // Slave is disabled
SetBits16(I2C_CON_REG, I2C_SPEED, speed); // Set speed
SetBits16(I2C_CON_REG, I2C_10BITADDR_MASTER, address_mode); // Set addressing mode
SetWord16(I2C_TAR_REG, dev_address & 0xFF); // Set Slave device address
SetWord16(I2C_ENABLE_REG, 0x1); // Enable the I2C controller
while(GetWord16(I2C_STATUS_REG) & 0x20); // Wait for I2C master FSM to be IDLE
}
int8_t SCC_I2C_bus_write(uint8_t dev_addr, uint8_t *reg_data, uint8_t count)
{
uint32_t SCC_i2c_timeout = SCC_I2C_TIMEOUT;
int32_t SCC_iERROR = SCC_INIT_VALUE;
//uint8_t array[I2C_BUFFER_LEN];
uint8_t stringpos = SCC_INIT_VALUE;
SetWord16(I2C_ENABLE_REG, 0x0);
SetWord16(I2C_TAR_REG, dev_addr & 0xFF); // Set Slave device address
SetWord16(I2C_ENABLE_REG, 0x1);
TIMEOUT_WAIT_UNTIL_I2C_FIFO_IS_EMPTY(SCC_i2c_timeout);
for (stringpos = SCC_INIT_VALUE; stringpos < count; stringpos++){
SEND_I2C_COMMAND(reg_data[stringpos]);
TIMEOUT_WAIT_UNTIL_I2C_FIFO_IS_EMPTY(SCC_i2c_timeout); // Wait if I2C Tx FIFO is full
}
TIMEOUT_WAIT_UNTIL_NO_MASTER_ACTIVITY(SCC_i2c_timeout); // Wait until no master activity
return (int8_t)SCC_iERROR;
}
int8_t SCC_I2C_bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
{
uint32_t SCC_i2c_timeout = SCC_I2C_TIMEOUT;
int32_t SCC_iERROR = SCC_INIT_VALUE;
uint8_t array[I2C_BUFFER_LEN] = {SCC_INIT_VALUE};
uint8_t stringpos = SCC_INIT_VALUE;
array[SCC_INIT_VALUE] = reg_addr;
SetWord16(I2C_ENABLE_REG, 0x0);
SetWord16(I2C_TAR_REG, dev_addr & 0xFF); // Set Slave device address
SetWord16(I2C_ENABLE_REG, 0x1);
TIMEOUT_WAIT_UNTIL_I2C_FIFO_IS_EMPTY(SCC_i2c_timeout);
(stringpos = 0;stringpos <计数;stringpos + +) {
TIMEOUT_WAIT_WHILE_I2C_FIFO_IS_FULL(SCC_i2c_timeout); // Wait if Tx FIFO is full
SEND_I2C_COMMAND(0x0100); // Set read access for times
}
// Critical section
GLOBAL_INT_DISABLE();
// Get the received data
(stringpos = 0;stringpos <计数;stringpos + +) {
TIMEOUT_WAIT_FOR_RECEIVED_BYTE(SCC_i2c_timeout); // Wait for received data
array[stringpos] =(0xFF & GetWord16(I2C_DATA_CMD_REG)); // Get the received byte
}
// End of critical section
GLOBAL_INT_RESTORE();
for (stringpos = SCC_INIT_VALUE; stringpos
Hi Mayank,
Since the master is the 580 then, this is the device that provides the clock in order to read the data back from the device, so please check via an analyser if the device actually produces the appropriate clock cycles in order to read 250 bytes from the external device. Each SEND_I2C_COMMAND() produces the clock in order for the device to read one byte from the external device, so as far as i am able to understand from the code that you have you send 250 reading commands all at once in the first for() loop (the TIMEOUT_WAIT_WHILE_I2C_FIFO_IS_FULL corresponds to the WAIT_WHILE_I2C_FIFO_IS_FULL macro) and then you are trying to read 250 bytes from the FIFO of the I2C but the FIFO of the i2c is only 32 bytes deep, so apparently you are reading only two sets of a full FIFO. Please check the i2c_eeprom example in the SDK and check how the code is accessing the memory device reading chunks of 32 bytes each in order to compy with the restriction of the i2c FIFO in a total amount of data of 256 bytes.
Thanks MT_dialog