---
title: "Read W5200 regs using SPI DMA"
url: "https://maker.wiznet.io/forum/11865"
markdown_url: "https://maker.wiznet.io/forum/11865/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "soumyaks"
created: "2016-05-13T08:19:20+09:00"
last_activity: "2017-05-04T08:38:51+09:00"
language: "en"
views: 929
replies: 0
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Read W5200 regs using SPI DMA

## Question

Asked by soumyaks on 2016-05-13 in Ethernet Chips.

Hi All,

I am able to read (W5200 registers) SHAR / SIPR / GAR one by one using a laborious DMA setup. I want to simplify this and read/write all the common registers once for all.

## Here is the code i am using to write/read SHAR register from a CC3200 Master device.

static uint8_t tx_buffer[DMA_SIZE];
static uint8_t rx_buffer[DMA_SIZE];
#define DMA_SIZE 10

uint8_t send_mac[10] = {0x00,0x09,0x80,0x14,0xFE,0xA8,0xD9,0xC0,0x18,0xF3};
uint8_t recv_mac[10] = {0x00,0x09,0x00,0x14,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

/* Setting the MAC Address through SPI DMA operation */

memcpy(tx_buffer,send_mac,sizeof(send_mac)); // Fill buffer with MAC address and W5200 Write Protocol Values
UDMASetupTransfer(UDMA_CH31_GSPI_TX,UDMA_MODE_BASIC,DMA_SIZE,
UDMA_SIZE_8,UDMA_ARB_1,
tx_buffer,UDMA_SRC_INC_8,
(void *)(GSPI_BASE + MCSPI_O_TX0),UDMA_DST_INC_NONE); // Setup DMA

SPICSEnable(GSPI_BASE); // Start transfer

while(transfer_status != COMPLETE) // Wait for transfer to complete
{
if (uDMAChannelModeGet (UDMA_CH31_GSPI_TX | UDMA_PRI_SELECT) == UDMA_MODE_STOP)
txdone = 1;
if (txdone)
{
SPICSDisable(GSPI_BASE);
transfer_status = COMPLETE;
}
}

/* Getting the MAC Address through SPI DMA operation */
memset(tx_buffer,0xFF,sizeof(tx_buffer)); // Fill buffer with Dummy Writes (0xFF)
memcpy(tx_buffer,recv_mac,sizeof(recv_mac)); // Fill buffer with W5200 Read Protocol Values

UDMASetupTransfer(UDMA_CH31_GSPI_TX,UDMA_MODE_BASIC,DMA_SIZE, //5byte command
UDMA_SIZE_8,UDMA_ARB_1,
tx,UDMA_SRC_INC_8,
(void *)(GSPI_BASE + MCSPI_O_TX0),UDMA_DST_INC_NONE);

UDMASetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,DMA_SIZE, //only 6 bytes!
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
rx,UDMA_DST_INC_8);

## SPICSEnable(GSPI_BASE);

For reading the common registers, I just change to 0x36 for the Write and Read protocol Length Values and DMA_SIZE macro.

But I do get all Zeros if I read anything in bulk. What setting am I missing? Please help.

Thanks much,
Soumya

---

Source: https://maker.wiznet.io/forum/11865
