I have Ethernet code that appears to work OK until I add this line of code
T = SPI4_Read(Buffer)
simply trying to read the SPI4 buffer causes my easyPIC Fusion board w/PIC32MX795F512L w/ENET to quit responding to pings.
I was unable to get Ethernet to work with my project so I modified the example code to create a small program to send some TCP data, after I had that working I tried to add reading data from SPI4 and I cannot get them to work together.
My code tries to send 208 bytes of TCP Data every few seconds, if you program it to the easyPIC fusion board and connect to 10.1.1.125 with the Chrome browser you can see my data being written to the chrome browser every few seconds.
Uncomment the line of code
"T = SPI4_Read(Buffer)"
recompile and it quits working.
I don't know how to attach files here..... so here is the code pasted in as text.
Code: Select all
program ENET_Card
' Declarations section
Dim i as word
Dim buffer, T as word
main:
' Main program
SPI4_Init_Advanced(_SPI_SLAVE,_SPI_8_BIT,64,_SPI_SS_DISABLE,
_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_ACTIVE_2_IDLE)
MCUInit()
EnableInterrupts
while(1)
If SPI4STAT.SPIRBE = 0 Then 'RECEIVE BUFFER NOT EMPTY
'*****************************************************************************
' T = SPI4_Read(Buffer) 'this line causes it to stop working
'*****************************************************************************
End If
Net_Ethernet_Intern_doPacket()
wend
end.
the Ethernet module code.........
'***************************************
Code: Select all
module ENET_Card_Send
Dim gChar As Char[208]
dim myMacAddr as byte[6] ' my MAC address
myIpAddr as byte[4] ' my IP address
gwIpAddr as byte[4] ' gateway (router) IP address
ipMask as byte[4] ' network mask (for example : 255.255.255.0)
dnsIpAddr as byte[4] ' DNS server IP address
remoteIpAddr as byte[4] 'host IP addr
socketTCP as ^SOCKET_Intern_Dsc
sendLCU as bit
''''''''''''''''''''''''''''''''''''''''
sub procedure Net_Ethernet_Intern_UserTCP(dim socket as ^SOCKET_Intern_Dsc)
sub function Net_Ethernet_Intern_UserUDP(dim udpDsc as ^UDP_Intern_Dsc) as word
sub procedure MCUInit()
sub procedure Timer1Int() iv IVT_TIMER_1 ilevel 7 ics ICS_SRS
sub procedure InitPHYPins()
implements
''''''''''''''''''''''''''''''''''''''''
sub procedure Net_Ethernet_Intern_UserTCP(dim socket as ^SOCKET_Intern_Dsc)
dim Dyna as Char[206]
'**************************
dim stemp as String [30]
dim itemp as Integer
'*****************************
If sendLCU = False Then 'this is a toggle to prevent it from doubling and sending the data twice
sendLCU = True
Exit
Else
sendLCU = FALSE
Dyna = "+3.5000000E+00,+0,+3.4000000E+00,+1,+3.3000000E+00,+2,+1.5700000E+01,+0,+1.5800000E+02,+0,+1.5900000E+01,+0,+0.0000000E+00,+0,+0.0000000E+00,+0,+0.0000000E+00,+0,+0.0000000E+00,+0,+0.0000000E+00,+0,+1,+0,+1"
Net_Ethernet_Intern_putbyteTCP(0xCE,socket) 'send 207
Net_Ethernet_Intern_putbyteTCP(0xCF,socket) 'send 206-num bytes to follow
Net_Ethernet_Intern_putStringTCP(@dyna,socket) 'data package of 206 bytes
End If
end sub
sub function Net_Ethernet_Intern_UserUDP(dim udpDsc as ^UDP_Intern_Dsc) as word
result = 0
end sub
dim cnt as word
' Initialization of Timer1
dim i as char
sub procedure MCUInit()
TMR1 = 0 ' reset timer value to zero
PR1 = 65535 ' Load period register
T1IP0_bit = 1 ' set interrupt
T1IP1_bit = 1 ' priority
T1IP2_bit = 1 ' to 7
TCKPS0_bit = 1 ' Set Timer Input Clock
TCKPS1_bit = 1 ' Prescale value to 1:256
EnableInterrupts() ' Enable all interrupts
T1IE_bit = 1 ' Enable Timer1 Interrupt
ON__T1CON_bit = 1 ' Enable Timer1
' set mac address
myMacAddr[0] = 0x00
myMacAddr[1] = 0x14
myMacAddr[2] = 0xA5
myMacAddr[3] = 0x76
myMacAddr[4] = 0x19
myMacAddr[5] = 0x3F
' set IP address
myIpAddr[0] = 10 '192
myIpAddr[1] = 1 '168
myIpAddr[2] = 1 '20
myIpAddr[3] = 125 '61
' set gateway address
gwIpAddr[0] = 10 '192
gwIpAddr[1] = 1 '168
gwIpAddr[2] = 1 '20
gwIpAddr[3] = 6
' set dns address
dnsIpAddr[0] = 10 '192
dnsIpAddr[1] = 1 '168
dnsIpAddr[2] = 1 '20
dnsIpAddr[3] = 2
' set subnet mask
ipMask[0] = 255
ipMask[1] = 255
ipMask[2] = 255
ipMask[3] = 0
'remote IP address
remoteIpAddr[0] = 10
remoteIpAddr[1] = 1
remoteIpAddr[2] = 1
remoteIpAddr[3] = 60
'**************************
InitPHYPins()
Net_Ethernet_Intern_stackInitTCP()
Net_Ethernet_Intern_Init(@myMacAddr, @myIpAddr, Net_Eth_Int_AUTO_NEGOTIATION and Net_Eth_Int_DEFAULT_MAC ) 'init ethernet board
Net_Ethernet_Intern_confNetwork(@ipMask, @gwIpAddr, @dnsIpAddr)
'******************************
while(i <> 1)
i = Net_Ethernet_Intern_connectTCP(@remoteIpAddr, 3000, 3000, @socketTCP)
wend
Delay_ms(1000)
end sub