WIZnet Developer Forum

W5200 atmega128 과 SPI 통신실패

아래의 코드로 16MHz ATMEGA128과 Wiz5200을 연결 했습니다.
MAC Address를 확인하면 초기화 되어있지 않습니다.
단 연결확인위해 5100에서 사용한 아래의 코드를 넣으면 5200으로부터 더미 데이터는 올라옵니다.
수정할 사항 확인 부탁 드립니다.

아래를 오픈하고 실행시
IINCHIP_SpiSendData(0x0F); //used by 5100

MAC ADDRESS : 00.08.dc.11.22.26
G/W IP ADDRESS : 192.168.10.1
SUBNET MASK : 255.255.255.0
LOCAL IP ADDRESS : 192.168.10.50
AVR :TCP SERVER, PORT : 5000

W5200 SPI mode Net Config Information

MAC ADDRESS : 20.56.c5.a6.80.62
G/W IP ADDRESS : 24.65.33.50
SUBNET MASK : 89.110.20.8
LOCAL IP ADDRESS : 25.64.146.131

AVR :TCP SERVER, PORT : 5000

아래를 막고하고 실행시
//IINCHIP_SpiSendData(0x0F); //used by 5100

======================
MAC ADDRESS : 00.08.dc.11.22.26
G/W IP ADDRESS : 192.168.10.1
SUBNET MASK : 255.255.255.0
LOCAL IP ADDRESS : 192.168.10.50
AVR :TCP SERVER, PORT : 5000
a3

W5200 SPI mode Net Config Information

MAC ADDRESS : 00.00.00.00.00.00
G/W IP ADDRESS : 0.0.0.0
SUBNET MASK : 0.0.0.0
LOCAL IP ADDRESS : 0.0.0.0

AVR :TCP SERVER, PORT : 5000

소스코드 참고:

// PB3(MISO), PB2(MOSI), PB1(SCK), PB0(/SS) // CS=1, waiting for SPI start // SPI mode 0, 4MHz
#define SPI0_Init0() DDRB |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT;
PORTB = 0x01;
SPCR = 0x50;
SPSR = 0x01;

#define IINCHIP_SpiInit SPI0_Init0

uint8 IINCHIP_WRITE(uint16 addr,uint8 data)
{
IINCHIP_ISR_DISABLE(); // Interrupt Service Routine Disable

//SPI MODE I/F
IINCHIP_CSoff();                            // CS=0, SPI start

// IINCHIP_SpiSendData(0x0F); //used by 5100

IINCHIP_SpiSendData((addr & 0xFF00) >> 8);  // Address byte 1
IINCHIP_SpiSendData(addr & 0x00FF);         // Address byte 2

IINCHIP_SpiSendData(0x80);                  // Data write command and Write data length 1
IINCHIP_SpiSendData(0x01);                  // Write data length 2

IINCHIP_SpiSendData(data);                  // Data write (write 1byte data)

IINCHIP_CSon();                             // CS=1,  SPI end

    IINCHIP_ISR_ENABLE();                       // Interrupt Service Routine Enable
return 1;

}
/**
@brief This function reads the value from W5200 registers.
*/
uint8 IINCHIP_READ(uint16 addr)
{
uint8 data;

IINCHIP_ISR_DISABLE();                       // Interrupt Service Routine Disable
	
IINCHIP_CSoff();                             // CS=0, SPI start

// IINCHIP_SpiSendData(0x0F); //used by 5100

IINCHIP_SpiSendData((addr & 0xFF00) >> 8);   // Address byte 1
IINCHIP_SpiSendData(addr & 0x00FF);          // Address byte 2

IINCHIP_SpiSendData(0x00);                   // Data read command and Read data length 1
IINCHIP_SpiSendData(0x01);                   // Read data length 2   	

IINCHIP_SpiSendData(0x00);            // Data read (read 1byte data)

data = SPI0_RxData();

IINCHIP_CSon();                              // CS=1,  SPI end

IINCHIP_ISR_ENABLE();                        // Interrupt Service Routine Enable
return data;

}

main()
{

IINCHIP_SpiInit();


IINCHIP_WRITE(MR, MR_RST);

wait_1ms(100);


printf_P("\r\nMAC ADDRESS      : ");

printf_P("%02x.%02x.%02x.%02x.%02x.%02x\r\n",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);	

IINCHIP_WRITE((SHAR0 + 0),mac[0]);

IINCHIP_WRITE((SHAR0 + 1),mac[1]);

IINCHIP_WRITE((SHAR0 + 2),mac[2]);

IINCHIP_WRITE((SHAR0 + 3),mac[3]);

IINCHIP_WRITE((SHAR0 + 4),mac[4]);

IINCHIP_WRITE((SHAR0 + 5),mac[5]);



printf_P("G/W IP ADDRESS   : ");

printf_P("%d.%d.%d.%d\r\n",gw[0],gw[1],gw[2],gw[3]);

IINCHIP_WRITE((GAR0 + 0),gw[0]);

IINCHIP_WRITE((GAR0 + 1),gw[1]);

IINCHIP_WRITE((GAR0 + 2),gw[2]);

IINCHIP_WRITE((GAR0 + 3),gw[3]);



printf_P("SUBNET MASK      : "); 

printf_P("%d.%d.%d.%d\r\n",sn[0],sn[1],sn[2],sn[3]);

IINCHIP_WRITE((SUBR0 + 0),sn[0]);

IINCHIP_WRITE((SUBR0 + 1),sn[1]);

IINCHIP_WRITE((SUBR0 + 2),sn[2]);

IINCHIP_WRITE((SUBR0 + 3),sn[3]);



printf_P("LOCAL IP ADDRESS : "); 

printf_P("%d.%d.%d.%d\r\n",ip[0],ip[1],ip[2],ip[3]);

IINCHIP_WRITE((SIPR0 + 0),ip[0]);

IINCHIP_WRITE((SIPR0 + 1),ip[1]);

IINCHIP_WRITE((SIPR0 + 2),ip[2]);

IINCHIP_WRITE((SIPR0 + 3),ip[3]);



printf_P("AVR :TCP SERVER, PORT : %d\r\n", port);

sysinit(txsize,rxsize);

	printf_P("============================================\r\n");

printf_P("   W5200 SPI mode  Net Config Information\r\n");

printf_P("============================================\r\n");



printf_P("MAC ADDRESS      : ");

tmp[0] = IINCHIP_READ(SHAR0+0);

tmp[1] = IINCHIP_READ(SHAR0+1);

tmp[2] = IINCHIP_READ(SHAR0+2);

tmp[3] = IINCHIP_READ(SHAR0+3);

tmp[4] = IINCHIP_READ(SHAR0+4);

tmp[5] = IINCHIP_READ(SHAR0+5);

printf_P("%02x.%02x.%02x.%02x.%02x.%02x\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);	



printf_P("G/W IP ADDRESS   : ");

tmp[0] = IINCHIP_READ(GAR0 + 0);

tmp[1] = IINCHIP_READ(GAR0 + 1);

tmp[2] = IINCHIP_READ(GAR0 + 2);

tmp[3] = IINCHIP_READ(GAR0 + 3);

printf_P("%d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]);



printf_P("SUBNET MASK      : "); 

tmp[0] = IINCHIP_READ(SUBR0 + 0);

tmp[1] = IINCHIP_READ(SUBR0 + 1);

tmp[2] = IINCHIP_READ(SUBR0 + 2);

tmp[3] = IINCHIP_READ(SUBR0 + 3);

printf_P("%d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]);



printf_P("LOCAL IP ADDRESS : "); 

tmp[0] = IINCHIP_READ(SIPR0 + 0);

tmp[1] = IINCHIP_READ(SIPR0 + 1);

tmp[2] = IINCHIP_READ(SIPR0 + 2);

tmp[3] = IINCHIP_READ(SIPR0 + 3);

printf_P("%d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]);



printf_P("====================================\r\n");

printf_P("AVR :TCP SERVER, PORT : %d\r\n", port);

printf_P("====================================\r\n");

}

해결하였습니다…
다른 드라이버에서 충돌이 있었습니다…

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.