UDP data send to PC from PIC without PC request
Posted: 03 May 2018 21:50
Hi, I have faced the problem to send UDP data to PC from PIC32MX795F512L without request from PC.
I wrote simple program
1. Ethernet_doPacket() while loop, whenever send any data from UDP Terminal, PIC send "UDP Transmition" Text.
It is working perfectly.
2. I used one switch which is connected to PORTE Bit 7. Whenever press the switch, Hellow message send to PC.
It is not working, UDP Terminal not receive any message.
I am a new to use pic microcontroller, Please help me. I have given my complete source code.
Please correct me what i made mistake.
unsigned char myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ; // my MAC address
unsigned char myIpAddr[4] = {192,168,20,60}; // PIC IP Address
unsigned char IpAddr[4] = {192, 168, 20, 200 }; // My PC IP address
typedef struct {
unsigned canCloseTCP: 1; // flag which closes socket
unsigned isBroadcast: 1; // flag which denotes that the IP package has been received via subnet broadcast address (not used for PIC16 family)
} TEthPktFlags;
unsigned int Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength, TEthPktFlags *flags)
{
Ethernet_putString("UDP Transmition");
return(15);
}
unsigned int Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, TEthPktFlags *flags)
{
return(0); // return to the library with the number of bytes to transmit
}
void main() {
TRISD11_bit = 0; // ETH_ALT_MDC_BIT
TRISD8_bit = 1; // ETH_ALT_MDIO_BIT
TRISA15_bit = 0; // ETH_ALT_TXEN_BIT
TRISD14_bit = 0; // ETH_ALT_TXD0_BIT
TRISD15_bit = 0; // ETH_ALT_TXD1_BIT
TRISG9_bit = 1; // ETH_ALT_RXCLK_BIT
TRISG8_bit = 1; // ETH_ALT_RXDV_BIT
TRISE8_bit = 1; // ETH_ALT_RXD0_BIT
TRISE9_bit = 1; // ETH_ALT_RXD1_BIT
TRISG15_bit = 1; // ETH_ALT_RXERR_BIT
TRISE7_bit = 1; // Switch
Ethernet_Init(myMacAddr, myIpAddr, _ETHERNET_AUTO_NEGOTIATION & _ETHERNET_DEFAULT_MAC);
while (1) {
if (PORTEbits.RE7 == 0){
Ethernet_UserUDP(IpAddr, 10001, 10001, "Hello", 5);
}
Ethernet_doPacket();
}
}
I wrote simple program
1. Ethernet_doPacket() while loop, whenever send any data from UDP Terminal, PIC send "UDP Transmition" Text.
It is working perfectly.
2. I used one switch which is connected to PORTE Bit 7. Whenever press the switch, Hellow message send to PC.
It is not working, UDP Terminal not receive any message.
I am a new to use pic microcontroller, Please help me. I have given my complete source code.
Please correct me what i made mistake.
unsigned char myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ; // my MAC address
unsigned char myIpAddr[4] = {192,168,20,60}; // PIC IP Address
unsigned char IpAddr[4] = {192, 168, 20, 200 }; // My PC IP address
typedef struct {
unsigned canCloseTCP: 1; // flag which closes socket
unsigned isBroadcast: 1; // flag which denotes that the IP package has been received via subnet broadcast address (not used for PIC16 family)
} TEthPktFlags;
unsigned int Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength, TEthPktFlags *flags)
{
Ethernet_putString("UDP Transmition");
return(15);
}
unsigned int Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, TEthPktFlags *flags)
{
return(0); // return to the library with the number of bytes to transmit
}
void main() {
TRISD11_bit = 0; // ETH_ALT_MDC_BIT
TRISD8_bit = 1; // ETH_ALT_MDIO_BIT
TRISA15_bit = 0; // ETH_ALT_TXEN_BIT
TRISD14_bit = 0; // ETH_ALT_TXD0_BIT
TRISD15_bit = 0; // ETH_ALT_TXD1_BIT
TRISG9_bit = 1; // ETH_ALT_RXCLK_BIT
TRISG8_bit = 1; // ETH_ALT_RXDV_BIT
TRISE8_bit = 1; // ETH_ALT_RXD0_BIT
TRISE9_bit = 1; // ETH_ALT_RXD1_BIT
TRISG15_bit = 1; // ETH_ALT_RXERR_BIT
TRISE7_bit = 1; // Switch
Ethernet_Init(myMacAddr, myIpAddr, _ETHERNET_AUTO_NEGOTIATION & _ETHERNET_DEFAULT_MAC);
while (1) {
if (PORTEbits.RE7 == 0){
Ethernet_UserUDP(IpAddr, 10001, 10001, "Hello", 5);
}
Ethernet_doPacket();
}
}