NET_Ethernet_Internal library problem while using SPI?

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
ChuckR
Posts: 34
Joined: 26 Feb 2014 21:30

NET_Ethernet_Internal library problem while using SPI?

#1 Post by ChuckR » 24 May 2016 14:43

I have been struggling to get Ethernet working and it appears the problem might be with the NET_Ethernet_Internal library.
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

ChuckR
Posts: 34
Joined: 26 Feb 2014 21:30

Re: NET_Ethernet_Internal library problem while using SPI?

#2 Post by ChuckR » 24 May 2016 14:53

My apologies, I failed to get all of the code pasted in and I don't see a way to edit or delete my first post.
This belongs at the bottom of the previous code.

Code: Select all

' Interrupt routine Timer1
dim timer_tmp1 as char
 sub procedure Timer1Int() iv IVT_TIMER_1 ilevel 7 ics ICS_AUTO
  timer_tmp1 = timer_tmp1 + 1
  Net_Ethernet_Intern_UserTimerSec = Net_Ethernet_Intern_UserTimerSec + 1
  if(timer_tmp1 = 10) then
    timer_tmp1 = 0
    '******************************************
    Net_Ethernet_Intern_startSendTCP(socketTCP)
    '******************************************
  end if
  TMR1 = 0
  T1IF_bit = 0  ' clear interrupt flag
end sub

sub procedure InitPHYPins()
  TRISD11_bit = 0    ' ETH_MDC_BIT
  TRISD8_bit = 1     ' ETH_MDIO_BIT
  TRISD6_bit = 0    ' ETH_TXEN_BIT
  TRISF1_bit = 0    ' ETH_TXD0_BIT
  TRISF0_bit = 0    ' ETH_TXD1_BIT
  TRISG9_bit = 1     ' ETH_RXCLK_BIT
  TRISG8_bit = 1     ' ETH_RXDV_BIT
  TRISB12_bit = 1     ' ETH_RXD0_BIT
  TRISB13_bit = 1     ' ETH_RXD1_BIT
  TRISB11_bit= 1    ' ETH_RXERR_BIT
end sub

End.

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: NET_Ethernet_Internal library problem while using SPI?

#3 Post by biljana.nedeljkovic » 03 Jun 2016 14:16

Hello,

I apologize for the late reply. Is this issue still relevant to you?

Can you explain more about it, you were able to make it work if you don't use SPI4 or not?

Best regards,
Biljana

ChuckR
Posts: 34
Joined: 26 Feb 2014 21:30

Re: NET_Ethernet_Internal library problem while using SPI?

#4 Post by ChuckR » 03 Jun 2016 21:48

Yes this issue is still relevant, and the problem is the same. The code works until you add the line of code that says to read the SPI buffer.

Post Reply

Return to “mikroBasic PRO for PIC32 General”