Help me for start with w5500 in udp mode
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Share projects and connect with makers.
Joined before the site update? first.
New to WIZnet Makers?
We sent a verification link to your address. Open it to activate your account, then log in.
Accounts from this email provider are reviewed by an administrator after verification. Approval usually takes one business day.
Already have an account?
Enter your email address. If it belongs to an account, we'll send a link to set a new password. Members who joined before the site update use this to set their password.
If an account uses that address, we sent a link to set a new password. The link works once and expires in 30 minutes.
Know your password?
Need an account?
RE: Help me for start with w5500 in udp mode
by vanvught ·
Hi,
You should not make any changes to the Wiznet code. The option is to create your own w5500.c file with the w5500_init function. You call this once and then you can use the socket functions. See an example below for the Raspberry Pi. You need to provide the static functions with the SPI code for your CPU/SoC.
-Arjan
RE: Help me for start with w5500 in udp mode
by acpie360 ·
As it’s been stated by vanvught, you don’t have to change the library source code. The chip select/de-select functions and SPI read/write functions can all be registered as callbacks using reg_wizchip_cs_cbfunc() and reg_wizchip_spi_cbfunc(). For all PIC micros, remember to always read from a PORT and write to a LAT.
In the ioLibrary’s “Internet” folder, there are DHCP client and DNS client source code files if you plan to use them. They also require you to provide a 1-second tick function for various time-out operation.
In general, your project should start out with PHY detection. Once PHY is active, run DHCP. Once an IP address is acquired, you can then run other TCP/UPD socket functions.
RE: Help me for start with w5500 in udp mode
by toran ·
Thanks for your response Dear friends
I want in UDP mode Send “Hello world!” by LAN port
My code is as follows
I could not do more than that
Please help me
thank you
#include <xc.h>
#define FCY 60000000UL
#include <libpic30.h>
#include <stdio.h>
#include <string.h>
#include “wizchip_conf.h”
#include “socket.h”
#include “w5500.h”
#include “uart1.h”
// FICD
#pragma config ICS = PGD1 // ICD Communication Channel Select bits (Communicate on PGEC1 and PGED1)
#pragma config JTAGEN = OFF // JTAG Enable bit (JTAG is disabled)
// FPOR
#pragma config ALTI2C1 = OFF // Alternate I2C1 pins (I2C1 mapped to SDA1/SCL1 pins)
#pragma config ALTI2C2 = OFF // Alternate I2C2 pins (I2C2 mapped to SDA2/SCL2 pins)
// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler bits (1:32,768)
#pragma config WDTPRE = PR128 // Watchdog Timer Prescaler bit (1:128)
#pragma config PLLKEN = ON // PLL Lock Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable bit (Watchdog timer enabled/disabled by user software)
// FOSC
#pragma config POSCMD = XT // Primary Oscillator Mode Select bits (XT Crystal Oscillator Mode)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function bit (OSC2 is clock output)
#pragma config IOL1WAY = OFF // Peripheral pin select configuration (Allow multiple reconfigurations)
#pragma config FCKSM = CSECMD // Clock Switching Mode bits (Clock switching is enabled,Fail-safe Clock Monitor is disabled)
// FOSCSEL
#pragma config FNOSC = FRC // Oscillator Source Selection (Internal Fast RC (FRC))
#pragma config IESO = OFF // Two-speed Oscillator Start-up Enable bit (Start up with user-selected oscillator source)
// FGS
#pragma config GWRP = OFF // General Segment Write-Protect bit (General Segment may be written)
void Init_SPI ( void )
{
// setup the SPI peripheral
SPI1STAT = 0x0; // disable the SPI module (just in case)
// SPI1CON1 = 0x0161; // FRAMEN = 0, SPIFSD = 0, DISSDO = 0, MODE16 = 0; SMP = 0; CKP = 1; CKE = 1; SSEN = 0; MSTEN = 1; SPRE = 0b000, PPRE = 0b01
// SPI1CON1bits.CKE = 0x00;
// SPI1CON1bits.CKP = 0x00;
SPI1STAT = 0x8000; // enable the SPI module
}
void Init_URAT (void)
{
TRISDbits.TRISD5 = 0; //TX1RS232 - RP69 - RD5 - GRP13
TRISDbits.TRISD4 = 0; //TX2RS232 - RP68 - RD4 - GRP12
}
// while(SPI1STATbits.SPITBF);
for(for_i = 0 ; for_i < len ; for_i++)
{
pBuf[for_i] = w5500_read();
}
}
for(for_i = 0 ; for_i < len ; for_i++)
{
w5500_write(pBuf[for_i]);
}
}
int main(void)
{
// Configure Oscillator to operate the device at 60Mhz
// Fosc= FinM/(N1N2), Fcy=Fosc/2
// Fosc= 8M60/(22)=120Mhz for 8M input clock
PLLFBD = 58; // M=60
CLKDIVbits.PLLPOST = 0; // N1=2
CLKDIVbits.PLLPRE = 0; // N2=2
OSCTUN = 0; // Tune FRC oscillator, if FRC is used
}
RE: RE: Help me for start with w5500 in udp mode
by acpie360 ·
If this is all you want to do, you can call the socket() API with Sn_MR_MACRAW, i.e., the MACRAW mode, and then call sendto() to send the “Hello world!” string.
RE: Help me for start with w5500 in udp mode
by toran ·
Thanks, acpie360
I have two problems:
1- When using the command:
wiz_NetInfo gWIZNETINFO = { .mac = {0x00, 0x08, 0xdc,0x00, 0xab, 0xcd},
.ip = {192, 168, 0, 226},
.sn = {255,255,255,0},
.gw = {192, 168, 0, 1},
.dns = {0,0,0,0},
.dhcp = NETINFO_STATIC };
ctlnetwork(CN_SET_NETINFO, (void*)&gWIZNETINFO);
And then I want to read parameters above by:
ctlnetwork(CN_GET_NETINFO, (void*)&gWIZNETINFO);
I see a different amount in the COM port terminal for debug !!!
The picture below is at the 7.5MHz SPI clock:
The picture below is at the 30MHz SPI clock:
=======================================================================
2- When I use the command to open the port:
socket(0,Sn_MR_UDP,3000,0);
The program stops at the same line of code and does not go to the next step !!!
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
This is all my code:
#include <xc.h>
#define FCY 60000000UL
#include <libpic30.h>
#include <stdio.h>
#include <string.h>
#define WIZCHIP 5500
#include “wizchip_conf.h”
#include “socket.h”
#include “w5500.h”
#include “uart1.h”
// FICD
#pragma config ICS = PGD1 // ICD Communication Channel Select bits (Communicate on PGEC1 and PGED1)
#pragma config JTAGEN = OFF // JTAG Enable bit (JTAG is disabled)
// FPOR
#pragma config ALTI2C1 = OFF // Alternate I2C1 pins (I2C1 mapped to SDA1/SCL1 pins)
#pragma config ALTI2C2 = OFF // Alternate I2C2 pins (I2C2 mapped to SDA2/SCL2 pins)
// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler bits (1:32,768)
#pragma config WDTPRE = PR128 // Watchdog Timer Prescaler bit (1:128)
#pragma config PLLKEN = ON // PLL Lock Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable bit (Watchdog timer enabled/disabled by user software)
// FOSC
#pragma config POSCMD = XT // Primary Oscillator Mode Select bits (XT Crystal Oscillator Mode)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function bit (OSC2 is clock output)
#pragma config IOL1WAY = OFF // Peripheral pin select configuration (Allow multiple reconfigurations)
#pragma config FCKSM = CSECMD // Clock Switching Mode bits (Clock switching is enabled,Fail-safe Clock Monitor is disabled)
// FOSCSEL
#pragma config FNOSC = FRC // Oscillator Source Selection (Internal Fast RC (FRC))
#pragma config IESO = OFF // Two-speed Oscillator Start-up Enable bit (Start up with user-selected oscillator source)
// FGS
#pragma config GWRP = OFF // General Segment Write-Protect bit (General Segment may be written)
void Init_SPI ( void )
{
// setup the SPI peripheral
SPI1STAT = 0x0; // disable the SPI module (just in case)
// SPI1CON1 = 0x0161; // FRAMEN = 0, SPIFSD = 0, DISSDO = 0, MODE16 = 0; SMP = 0; CKP = 1; CKE = 1; SSEN = 0; MSTEN = 1; SPRE = 0b000, PPRE = 0b01
// SPI1CON1bits.CKE = 0x00;
// SPI1CON1bits.CKP = 0x00;
SPI1STAT = 0x8000; // enable the SPI module
}
void Init_URAT (void)
{
TRISDbits.TRISD5 = 0; //TX1RS232 - RP69 - RD5 - GRP13
TRISDbits.TRISD4 = 0; //TX2RS232 - RP68 - RD4 - GRP12
}
////////////////////////////////////////////////
// Shared Buffer Definition for LOOPBACK TEST //
////////////////////////////////////////////////
// while(SPI1STATbits.SPITBF);
for(for_i = 0 ; for_i < len ; for_i++)
{
pBuf[for_i] = w5500_read();
}
}
for(for_i = 0 ; for_i < len ; for_i++)
{
w5500_write(pBuf[for_i]);
}
}
void network_init(void)
{
uint8_t tmpstr[6];
ctlnetwork(CN_SET_NETINFO, (void*)&gWIZNETINFO);
}
int main(void)
{
// Configure Oscillator to operate the device at 60Mhz
// Fosc= FinM/(N1N2), Fcy=Fosc/2
// Fosc= 8M60/(22)=120Mhz for 8M input clock
PLLFBD = 58; // M=60
CLKDIVbits.PLLPOST = 0; // N1=2
CLKDIVbits.PLLPRE = 0; // N2=2
OSCTUN = 0; // Tune FRC oscillator, if FRC is used
/*
wiz_NetInfo netInfo = { .mac = {0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef}, // MAC address
.ip = {10, 4, 33, 244}, // IP address
.sn = {255, 255, 255, 0}, // IP netmask
.gw = {10, 4, 33, 1}}; // IP gateway
*/
uint8_t memsize[2][8] = {{2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}};
uint8_t txsize[8] = {2,2,2,2,2,2,2,2};
uint8_t rxsize[8] = {2,2,2,2,2,2,2,2};
while( 1 )
{
// Write_SPI(0x07);
PORTCbits.RC13 = 1;
__delay_ms(500);
PORTCbits.RC13 = 0;
__delay_ms(500);
// WIZCHIP_WRITE(0x0402 ,0xff);
// WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb );
// result = socket(0, Sn_MR_UDP, 3000, SF_IO_NONBLOCK);
// printf(“socket Result: %d\r\n”, result);
// sendto(0, testBuffer, strlen(testBuffer), address, 300);
// printf(“sendto Result: %d\r\n”, result);
// __delay_ms(1000);
//
// loopback_udps(1,testBuffer,3000);
// __delay_ms(1000);
}
}
RE: Help me for start with w5500 in udp mode
by toran ·
What are my code bugs?
please tell me
RE: RE: Help me for start with w5500 in udp mode
by vanvught ·
It would be interesting to know the result of the wizchip_init. For example:
RE: Help me for start with w5500 in udp mode
by vanvught ·
Please note issue #44
RE: Help me for start with w5500 in udp mode
by acpie360 ·
I’d check the SPI RX buffer flag before reading the buffer, e.g.,