我使用的是基于 ARM7TDMI 的 NXP LH79525 处理器。有一个 EEPROM 通过 SPI 总线连接到 SSP 端口。
目标是将 EEPROM 读入 SRAM 中以实现更快的访问。
目前的工作代码向EEPROM发送一个读命令,一个字节一个字节地读取数据,这需要很长时间。
我想使用DMA直接读取SPI总线上的EEPROM,而不需要CPU的干预。
这是我的代码片段:
// Initialize the DMA for use with SPI bus.
// Source is the EEPROM on the SPI bus.
// Destination is "buffer".
p_dma_stream_2->source_low = 0U;
p_dma_stream_2->source_high = 0U;
const uint32_t dest_addr = (uint32_t) buffer;
p_dma_stream_2->dest_low = (dest_addr & 0xFFFFU);
p_dma_stream_2->dest_high = (dest_addr >> 16U);
p_dma_stream_2->max_count = bytesToRead;
*p_dma_intr_mask = 0U; // Disable all dma interrupts.
*p_dma_intr_clear = 0xFF; // Clear the interrupts.
SSP->dmacr = 0x01; // Enable reading with DMA
p_dma_stream_2->control = 0x06U; // + 0x01 to enable transfer.
// 0x400 - status of stream 2. 1 == stream is active.
uint32_t status = *p_dma_status;
while ((status & 0x400U) != 0U)
{
OSTimeDelay(10U); // 10 milliseconds
status = *p_dma_status;
}
使用上述示例时,我从 EEPROM 读取了不正确的值。
DMA 寄存器计数正确。
SSP 在此代码片段之前已初始化,用于读取字节。
我正在寻找有效的代码示例片段,但尚未在网络上找到。
最佳答案
根据这个User's Guide表 5-1 看起来 SSPRX 分配给 Stream 0 并且仅支持半字源数据宽度(表 5-15)。
您的代码似乎使用 Stream 2 和字节寻址。
关于c - 使用 DMA 读取 SPI (SSP) 总线上的 EEPROM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22544603/