void InitIO() { IO_OUTPUT(DATA_OUT_TRIGGER_PIN); ANSELBIT(DATA_OUT_TRIGGER_AN_PIN) = 0; IO_OUTPUT(ALERT_PIN); ANSELBIT(ALERT_AN_PIN) = 0; IO_OUTPUT(DATA_OUT0_PIN); ANSELBIT(DATA_OUT0_AN_PIN) = 0; IO_OUTPUT(DATA_OUT1_PIN); // ANSELBIT(DATA_OUT0_AN_PIN) = 0; IO_OUTPUT(DATA_OUT2_PIN); ANSELBIT(DATA_OUT0_AN_PIN) = 0; IO_OUTPUT(DATA_OUT3_PIN); ANSELBIT(DATA_OUT0_AN_PIN) = 0; IO_INPUT(DATA_IN0_PIN); ANSELBIT(DATA_IN0_AN_PIN) = 0; IO_INPUT(DATA_IN1_PIN); ANSELBIT(DATA_IN1_AN_PIN) = 0; IO_INPUT(DATA_IN2_PIN); // ANSELBIT(DATA_IN2_AN_PIN) = 0; IO_INPUT(DATA_IN3_PIN); // ANSELBIT(DATA_IN3_AN_PIN) = 0; }
void ethInit() { // configure SPI RCC->APB1ENR |= RCC_APB1ENR_SPI2EN; IO_PUSH_PULL(CS); IO_ALT_PUSH_PULL(SCK); IO_ALT_PUSH_PULL(MOSI); IO_INPUT(MISO); SPI2->CR1 = //SPI_CR1_BR_0 | //SPI_CR1_BR_1 | SPI_CR1_BR_0 | SPI_CR1_MSTR | SPI_CR1_SPE | SPI_CR1_SSM | SPI_CR1_SSI; IO_INPUT_PP(INT_ETH); IO_HIGH(INT_ETH); // configure module _delay_ms(100); enc28j60Reset(); _delay_ms(500); eth_initRegisters(); struct ip_addr ip_addr; struct ip_addr net_mask; struct ip_addr gw_addr; // IP4_ADDR(&ip_addr, _IP_ADDR[0], _IP_ADDR[1], _IP_ADDR[2], _IP_ADDR[3]); // IP4_ADDR(&net_mask, _IP_MASK[0], _IP_MASK[1], _IP_MASK[2], _IP_MASK[3]); // IP4_ADDR(&gw_addr, _IP_GW[0], _IP_GW[1], _IP_GW[2], _IP_GW[3]); myprintf("lwip_init\r\n"); lwip_init(); myprintf("lwip_init done\r\n"); eth_netif.hwaddr[0] = _HW_ADDR[0]; eth_netif.hwaddr[1] = _HW_ADDR[1]; eth_netif.hwaddr[2] = _HW_ADDR[2]; eth_netif.hwaddr[3] = _HW_ADDR[3]; eth_netif.hwaddr[4] = _HW_ADDR[4]; eth_netif.hwaddr[5] = _HW_ADDR[5]; // netif_add(ð_netif, &ip_addr, &net_mask, &gw_addr, 0, enc28j60_if_init, ip_input); netif_add(ð_netif, 0, 0, 0, 0, enc28j60_if_init, ip_input); myprintf("netif_add done\r\n"); netif_set_default(ð_netif); myprintf("netif_set_up done\r\n"); eth_udppcb = udp_new(); struct ip_addr addr; udp_bind(eth_udppcb, IP_ADDR_ANY, LOCAL_PORT); IP4_ADDR(&addr, _IP_SRV[0], _IP_SRV[1], _IP_SRV[2], _IP_SRV[3]); udp_connect(eth_udppcb, &addr, SRV_PORT); udp_recv(eth_udppcb, ð_onUDPDataReceived, 0); }