c - 使用 DMA 读取 SPI (SSP) 总线上的 EEPROM

标签 c embedded dma eeprom ssp

我使用的是基于 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/

相关文章:

c - C中的数据封装

linux - 内核或用户空间是否负责旋转帧缓冲区以匹配屏幕

ios - 嵌入式设备上可通过 iOS 访问的 WebService

linux - 复制到 DMA 缓冲区时,memcpy() 在 __memcpy_neon 中挂起

c - 覆盆子 : how does the PWM via DMA work?

c - 我必须在字符串中找到字母

c++ - 绘制 N 宽线?

c - C99 预处理器中的 static_if

linux - 同时 DMA 到用户内存

c - DMA 传输比 CPU 传输花费更多时间