Using HAL_I2C_transmit/receive_DMA inside a callback function
Hi everybody, I am trying to implement callback function for I2C peripheral.
This is the code without dma implementation:
void ADXL345_GetXyzRAW(uint8_t *buffer){
uint8_t firstRegAddress = ADXL345_DATAX0;HAL_I2C_Master_Transmit(ADXL345_I2C,
(uint8_t)(ADXL345_ADDRESS<<1), &firstRegAddress, 1, ADXL345_I2C_TIMEOUT_TRANSFER);HAL_I2C_Master_Receive(ADXL345_I2C,
(uint8_t)(ADXL345_ADDRESS<<1), buffer, 6, ADXL345_I2C_TIMEOUT_TRANSFER);}
As you can see, the code works properly but it demands cpu cycles. So my objective is to use dma controller for automatizing the process. The problem rise when the task
ADXL345_GetXyzRAW
demand me two i2c functions (transmit and receive).It is a problem because my idea is execute
ADXL345_GetXyzRAW function once and then still doing another task. It doens't allow me wait for ending of I2C transmit for then executing i2c receive (time is gold for my device). I need both of theses task executing one by one with out wait for the first for then execute the second in a polling mode.
My idea is
call the function
i2c receive dmainside
HAL_I2C_MasterTxCpltCallback(), but i dont know if I am doing a bad practice or a violation for access memory.
#hal #stm32 #dma #callback #i2c