Hi,
I am using I2C to communicate with a sensor, and need to use DMA for a high-bandwidth read operation.
I am able to get the sensor ready to send the data, and can see the data being transmitted if I write 0x0100 to I2C_DATA_CMD_REG (as is done in i2c_eeprom.c).
What I have not yet managed is to use the DMA to complete this exchange. I can queue several reads by writing to I2C_DATA_CMD_REG more than once, but I haven't worked out if I can
have the DMA automate the process.
Can anyone tell me what I need to do to get data out of an I2C slave by DMA?
Thank you,
埃里克
Keywords:
Device:
Hi Eric,
There is no example for using the I2C with the DMA, in order to get this to work in a read for example you will need to write the address of the slave that you would like to read, manually, in order for the device to output the address of the slave and the slave's register, and the above should be done quick enough in order to the module not to send a STOP condition. So you will have to configure two DMA channels in order to write and read, you will need to set up a channel that will have as source the the I2C_DATA_CMD_REG and as a destination the buffer (use DMA_setup struct in order to pass the configurations). After setting up the receiving side you will need to setup a transmit channel in order to send from the DMA to the I2C module in order to generate the clocks by writing to the I2C_DATA_CMD_REG the value 0x100 set the bit for reading and generate the clock. So the source address of the second channel would be a variable with the value 0x100 and the destination address will be the I2C_DATA_CMD_REG. After you have set up the the channels initialize them via the dma_initialization_function() (should be invoked two times one for each channel) and then enable the DMA via the dma_channel_enable() (again two invokations one for each channel). So after completing with the setting up of the DMA's you will have to send manualy the write command, and after that enable the DMA by SetWord16(I2C_DMA_CR_REG,TDMAE+RDMAE);
Thanks MT_dialog