plusk01 / airdamon_f3

Be the Matt Damon of the skies
2 stars 1 forks source link

SPI MPU6500 using DMA w/ Tx ISR: data is shifted #3

Closed plusk01 closed 6 years ago

plusk01 commented 6 years ago

When using DMA-enabled SPI and using the Tx channel ISR (DMA1_Channel3_IRQn), the data that received from the MPU seems to be shifted by 4 bytes.

If I disable the interrupt and instead just wait for the transfer to complete, I get the right result.

// wait for completion
while (DMA_GetFlagStatus(DMA1_FLAG_TC2) == RESET);
transfer_complete_isr();

Thus, it seems to be directly related to the DMA_ITConfig(cfg_->Tx_DMA_Channel, DMA_IT_TC, ENABLE) interrupt.

plusk01 commented 6 years ago

I fixed this issue by instead using the transfer transfer complete (DMA_IT_TC) interrupt on the Rx side (DMA1_Channel2_IRQn) (which makes intuitive sense -- before the uC was being interrupted after it finished transmitting, but not necessarily after it received all the data from the MPU).

SPI with DMA and interrupts is now working.

plusk01 commented 6 years ago

Note! The reason this issue came up in the first place was because I set the SPI clock to ~500 kHz for configuration, but never increased the clock for data transfer. I tested setting the clock to 18 MHz while using the Tx DMA_IT_TC (DMA1_Channel3_IRQn) and it worked just fine.

I'll leave SPI using Rx since it is more intuitive.