Hello,
I'm trying to read an I2C sensor using DMA and interrupts to minimize CPU load on a TMS570LS3137.
The sensor is read much like an EEPROM where the register address is sent first, then after a re-start all the data is clocked out, and finally the stop condition is sent.
I began by modifying the Re-Start example on the I2C Wiki page to read the sensor data. Here's the simplified version:
/* Transmit the register address */
i2cREG1->CNT = 1u;
i2cREG1->MDR = I2C_RESET_OUT | I2C_MASTER | I2C_TRANSMITTER | I2C_START_COND;
i2cREG1->DXR = regAddress;
while((i2cREG1->STR & (I2C_TX | I2C_ARDY)) == 0u); /* Wait for TX */
/* Re-start in receive mode*/
i2cREG1->CNT = count;
i2cREG1->MDR = I2C_RESET_OUT | I2C_MASTER | I2C_RECEIVER | I2C_START_COND |
I2C_STOP_COND;
/* Receive the data */
for (i = 0; i < count; i++) {
while ((i2cREG1->STR & I2C_RX) == 0u); /* Wait for Rx */
data[i] = i2cREG1->DRR;
}
It works fine but is not practical with all the waits, so next I setup DMA to receive all the data from I2CDRR. The DMA works too, so the "Receive the data" part in the above code goes away.
The final part of my task is to use an interrupt to remove the "Wait for TX". I thought it would be relatively simple to get a TXRDY interrupt after the register address is sent, and perform the "Re-start in receive mode" in the ISR. But I enable TXRDY_INT and I never get the interrupt. After some experimenting I found that I can get the TXRDY interrupt if I set my initial count to so that it doesn't reach zero after sending the address, but then the read operation fails so that can't be right.
Can anyone suggest how I would use an interrupt to perform the re-start after the address byte is transmitted? Perhaps TXRDY is not the right interrupt source.
Thanks, Bryan