Porting Issue - What should i2c_write and i2c_read do?

By felipebazura , 25 August 2014

I am using MPU 9250, Motion Driver 6.0, and Arm Cortex M-0.
I am wondering how the i2c write and read functions should be implemented. I notice that when you load the dmp image, there are chunks of multiple bytes being written to the mem_r_w register. Should my i2c_write function contain a for loop with multiple i2c writes. Or should I have a starting address and then write 'length' number of bytes after that.

Also, is there anyone out there who has a current working implementation on on the M-0

robert_valvonis

11 years 6 months ago

Hi,
You should write your I2C driver with a repeated start condition to write the DMP firmware memory in chunks. Below is the code snippet for ATSAM4LS4A which is M4 processor to setup TWI read operation with repeated start condition. (Note that TWI is from ATMEL and compatible with I2C)

transfer.bus->TWIM_CR = TWIM_CR_MDIS;

transfer.bus->TWIM_IDR = ~0UL;
transfer.bus->TWIM_SCR = ~0UL;

transfer.bus->TWIM_CR = TWIM_CR_MEN;
transfer.bus->TWIM_CR = TWIM_CR_SWRST;
transfer.bus->TWIM_CR = TWIM_CR_MDIS;

transfer.bus->TWIM_CMDR = TWIM_CMDR_NBYTES(sizeof(reg));
transfer.bus->TWIM_CMDR |= TWIM_CMDR_VALID;
transfer.bus->TWIM_CMDR |= TWIM_CMDR_START;
transfer.bus->TWIM_CMDR |= TWIM_CMDR_SADR(dev);

transfer.bus->TWIM_NCMDR = TWIM_NCMDR_NBYTES(count);
transfer.bus->TWIM_NCMDR |= TWIM_NCMDR_VALID;
transfer.bus->TWIM_NCMDR |= TWIM_NCMDR_STOP;
transfer.bus->TWIM_NCMDR |= TWIM_NCMDR_START;
transfer.bus->TWIM_NCMDR |= TWIM_NCMDR_READ;
transfer.bus->TWIM_NCMDR |= TWIM_NCMDR_SADR(dev);

phpbb Post ID
25674
phpbb Topic ID
16509