WIZnet Developer Forum

Wiz550io 으로 테스트 중인데요 소스 좀 봐주세요

W5500 으로 보드 제작 하기 전에

wiz550io 사서 테스트 중인데요

잘 안되네요

사용 보드는 STM32F407 사용 한 보드입니다

소스는 아래 두 파일만 수정했고

기본 드라이버는 손대지 않았습니다

일단 ping가게 할려고 하는데 안되네요 ㅠㅠ

혹시 SPI 설정쪽이 문제인가 싶어 SPI 통신 나가는건 로직 애널라이즈로 확인했습니다

실례가 안된다면 잘못된 부분 있는지 봐주실수 있을까요?

감사합니다^^

아 그리고 WIZ550io 의 RDY, INTn 핀은 연결하지 않았습니다

----- w5500_init.h -----
#define W5500_SPI SPI1
#define W5500_SPI_CLK RCC_APB2Periph_SPI1

#define W5500_SPI_SCK_PIN GPIO_Pin_5
#define W5500_SPI_SCK_PORT GPIOA
#define W5500_SPI_SCK_GPIO_CLK RCC_AHB1Periph_GPIOA

#define W5500_SPI_MISO_PIN GPIO_Pin_6
#define W5500_SPI_MISO_PORT GPIOA
#define W5500_SPI_MISO_GPIO_CLK RCC_AHB1Periph_GPIOA

#define W5500_SPI_MOSI_PIN GPIO_Pin_7
#define W5500_SPI_MOSI_PORT GPIOA
#define W5500_SPI_MOSI_CLK RCC_AHB1Periph_GPIOA

#define W5500_CS_PIN GPIO_Pin_3
#define W5500_CS_GPIO_PORT GPIOA
#define W5500_CS_GPIO_CLK RCC_AHB1Periph_GPIOA

#define W5500_RESET_PIN GPIO_Pin_2
#define W5500_RESET_GPIO_PORT GPIOA
#define W5500_RESET_GPIO_CLK RCC_AHB1Periph_GPIOA

static uint8_t wizchip_rw(uint8_t byte);
static void wizchip_select(void);
static void wizchip_deselect(void);
static void wizchip_write(uint8_t wb);
static uint8_t wizchip_read(void);
void W5500_Init();
void Network_Config();
----- w5500_init.h -----

----- w5500_init.c -----
#include <stdio.h>
#include “stm32f4xx.h”
#include “w5500_init.h”
#include “wizchip_conf.h”

static uint8_t wizchip_rw(uint8_t byte)
{

while(SPI_I2S_GetFlagStatus(W5500_SPI, SPI_I2S_FLAG_TXE) == RESET); 
SPI_I2S_SendData(W5500_SPI, byte);	    
    
while(SPI_I2S_GetFlagStatus(W5500_SPI, SPI_I2S_FLAG_RXNE) == RESET); 	
return SPI_I2S_ReceiveData(W5500_SPI);	

}

static void wizchip_select(void)
{
GPIO_ResetBits(W5500_CS_GPIO_PORT, W5500_CS_PIN);
}

static void wizchip_deselect(void)
{
GPIO_SetBits(W5500_CS_GPIO_PORT, W5500_CS_PIN);
}

static void wizchip_write(uint8_t wb)
{
wizchip_rw(wb);
}

static uint8_t wizchip_read(void)
{
return wizchip_rw(0xFF);
}

void W5500_Init()
{
usart_tx_string(USART1,“s7”,2);
wizchip_deselect();

      //add callback function
      reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
      reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);
      
      uint8_t tmp;
      uint8_t memsize[2][8] = { {2,2,2,2,2,2,2,2}, {2,2,2,2,2,2,2,2} };
        
      if(ctlwizchip(CW_INIT_WIZCHIP,(void*)memsize) == -1)
      {
              //printf("WIZCHIP Initialized fail");
              return;
      }
      
      do
      {
              if(ctlwizchip(CW_GET_PHYLINK, (void*)&tmp) == -1)
              {
                      //printf("Unknown PHY Link status");
                      return;
                      
              }
      } while(tmp == PHY_LINK_OFF);

}

void Network_Config()
{
wiz_NetInfo gWIZNETINFO =
{
{0x00,0x08,0xdc,0x1f,0x17,0xcc},
{192,168,0,10},
{255,255,255,0},
{192,168,0,1},
{8,8,8,0},
};

    ctlnetwork(CN_SET_NETINFO, (void*) &gWIZNETINFO);

}
----- w5500_init.c -----

----- main.c -----
#include “stm32f4xx.h”
#include “w5500_init.h”

volatile uint16_t sys_tick_cnt;
void SPI_Init_Config();

void TimingDelay_Decrement()
{
if(sys_tick_cnt)
sys_tick_cnt–;

}

void SPI_Init_Config()
{
unsigned int i=0;
RCC_APB2PeriphClockCmd(W5500_SPI_CLK,ENABLE); // SPI1 클럭 ENABLE
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // SPI1이 GPIOA니깐 GPIOA 클럭도 ENABLE 해줘야 됨

GPIO_InitTypeDef  GPIO_InitStructure;                 // GPIO INIT STRUCT
SPI_InitTypeDef  SPI_InitStructure;


//---GPIO 핀 SPI로 설정, 안해주면  SPI가 아닌 일반 GPIO로 작동하는듯
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);

//--- SPI1 GPIO SETTING---, SPI1 GPIO 설정, MOSI, SCK
GPIO_InitStructure.GPIO_Pin = W5500_SPI_SCK_PIN | W5500_SPI_MOSI_PIN | W5500_SPI_MISO_PIN;    // GPIO PIN SELECT
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;    // GPIO SPEED SELECT     
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;         // GPIO Alternate function Mode
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;        // GPIO push-pull&open-drain Select - GPIO_OType_PP, GPIO_OType_OD
GPIO_Init(W5500_SPI_SCK_PORT, &GPIO_InitStructure);                // GPIO Init
//--- SPI1 GPIO SETTING---
    
    

//--- W5500 CS, RESET GPIO SETTING---, SPI1 GPIO 설정
GPIO_InitStructure.GPIO_Pin = W5500_CS_PIN | W5500_RESET_PIN;    // GPIO PIN SELECT
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;    // GPIO SPEED SELECT     
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;         // GPIO Alternate function Mode
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;        // GPIO push-pull&open-drain Select - GPIO_OType_PP, GPIO_OType_OD
    
GPIO_Init(W5500_CS_GPIO_PORT, &GPIO_InitStructure);                // GPIO Init
//--- SPI1 GPIO SETTING---
    
    
    GPIO_SetBits(W5500_CS_GPIO_PORT, W5500_RESET_PIN);
    GPIO_SetBits(W5500_CS_GPIO_PORT, W5500_CS_PIN);
    


//--- SPI1 SETTING ---
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;		// SPI 속도 설정
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(W5500_SPI, &SPI_InitStructure);
  
//--- SPI1 SETTING ---

SPI_Cmd(W5500_SPI, ENABLE);
    
    
    GPIO_ResetBits(W5500_RESET_GPIO_PORT,W5500_RESET_PIN);
    for(i=0;i<65000;i++);
    GPIO_SetBits(W5500_RESET_GPIO_PORT,W5500_RESET_PIN);

}

int main(void)
{
int i=0;

SPI_Init_Config();
    W5500_Init();
    Network_Config();

while(1)
{
	
}

}
----- main.c -----

안녕하세요.

우선 제가 참조하는 코드를 확인해주세요.

저희 강의할 때 사용되는 보드에 있는 코드입니다.

직접 구동되는거 확인했구요. 직접 말씀드리는 것 보단 코드를 비교해보시는게 괜찮을 것 같습니다.

peripheral clock 선언 제대로 하셨나 다시 확인해주시구요.

GPIO pin과 spi 선언핀들의 역할을 다시 확인해주세요.

void W5500_select(void)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_4); // Chip Select (Low)
}

void W5500_deselect(void)
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); // CS high
}

uint8_t W5500_read(void)
{
//Is FullDuplex
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); // TXE reset -> Send data(DR register)
SPI_I2S_SendData(SPI1, 0xff);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); // RXNE reset -> Data receive
return SPI_I2S_ReceiveData(SPI1);
}

void W5500_write(uint8_t byte)
{
//Is FullDuplex
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, byte);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
SPI_I2S_ReceiveData(SPI1);
}

// SPI Pin Enable and SPI Signal Configuration
void W5500HardwardInitilize(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;

// RCC Clock initial
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOA, ENABLE);

// SPI singal GPIO initial
// CLK pin enable
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; // Hardware Pin
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // External clock
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); // mapping

//MISO pin enable
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // Master in Slave out -> Floating = high Impedence
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

//MOSI pin enable
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // Master Out Slave in (Slave is external)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

//CS pin enable
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // GPIO_Mode_Out_OD - open drain (open collect) -> It's want Pull up resistor
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

//RESET pin enable
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // M3 (Master) -> W5500 (Slave)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);

//INT pin enable
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // internal Pull up
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);

// SPI initialization
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // SPI is Fullduplex communication
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; // Cortex-M3
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; // DFF bit / SPI is 1byte Transmission
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // First Start clock is 1(high) CPOL = 1
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // CPHA = 1
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // Software Slave Select
//BaudRate - 1sec = 1,000,000,000nsec , Frequency = 36Mhz --> 1/F=T --> 27.77nsec
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; // fpclk/2 -> W5500 chip is possible 80Mhz SPI communication. So,36Mhz communication.
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // Out of MSB trans
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);

// SPI Enable
SPI_Cmd(SPI1, ENABLE);

//H/WReset
W5500HARDWARDRESET();

}

// H/W Reset
void W5500HARDWARDRESET(void)
{
int i,j;
GPIO_WriteBit(GPIOD,GPIO_Pin_10,Bit_SET);
GPIO_WriteBit(GPIOD,GPIO_Pin_10,Bit_RESET);
for(i = 0; i < 10000 ; i++){j++;}
GPIO_WriteBit(GPIOD,GPIO_Pin_10,Bit_SET);
}

// Connect to MCU
void W5500_Init(void)
{
uint8_t tmp;
// Socket txbuffer , rxbuffer size
uint8_t memsize[2][8] = { { 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 2, 2, 2, 2, 2, 2, 2 } };

W5500_deselect();
W5500_select();

reg_wizchip_spi_cbfunc(W5500_read, W5500_write); // SPI call back function
reg_wizchip_cs_cbfunc(W5500_select, W5500_deselect); // CS call back function


/* wizchip initialize*/
if (ctlwizchip(CW_INIT_WIZCHIP, (void*) memsize) == -1) {
	printf("WIZCHIP Initialized fail.\r\n");
	while (1);
}

do { // check phy status
	if (ctlwizchip(CW_GET_PHYLINK, (void*) &tmp) == -1){ // Just Link led blink
		printf("Unknown PHY Link stauts.\r\n");
	}
} while (tmp == PHY_LINK_OFF);

}

안녕하세요.

먼저 동일한 네트워크 환경인지 확인해보시기 바랍니다.

IP를 192.168.0.10으로 하셨던데 PING을 쏘는 주체(pc겠죠?)도 192.168.0.??와 같은 IP 주소를 가져야 합니다.

그 후 spi통신을 wiz550io에 정상적으로 값이 써지는 지도 확인을 하셔야합니다.

일반적으로 네트워크 정보를 입력한 후 다시 읽어 printf등을 사용해 화면에 뿌려보는 방식으로 테스트합니다.

링크가 잡히는지도 확인하셔야합니다.(RJ-45의 led가 깜빡거리는 것으로 확인이 가능합니다.)

네트워크를 하려면 코딩 이외에도 여러가지 소소하게 신경써야하는 부분이 많습니다.

좋은 소식 있기를 기대합니다. :slight_smile:

감사합니다.

답변 정말 감사합니다

SPI 문제 였던거 같습니다^^

안녕하세요.

해결되서 다행입니다~

좋은 결과 있으시길 바랍니다.

안녕하세요.

해결되서 다행입니다.

좋은 결과 있으시길 바랍니다.

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