ENC424J600

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
fzanoto
Posts: 225
Joined: 25 Jul 2006 13:53

ENC424J600

#1 Post by fzanoto » 16 Mar 2012 14:50

In Enc424J600
what RESET pin ?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: ENC424J600

#2 Post by filip » 19 Mar 2012 10:09

Hi,

I believe I have answered you here :
http://www.mikroe.com/forum/viewtopic.p ... 6#p182876-

Regards,
Filip.

fzanoto
Posts: 225
Joined: 25 Jul 2006 13:53

Re: ENC424J600

#3 Post by fzanoto » 02 Apr 2012 20:56

See new error

Error:
Attachments
Enc424J600.JPG
Enc424J600.JPG (113.75 KiB) Viewed 4371 times

fzanoto
Posts: 225
Joined: 25 Jul 2006 13:53

Re: ENC424J600

#4 Post by fzanoto » 03 Apr 2012 12:59

hardware:
Attachments
aquisitor_DSP_eth_2011_424J600.JPG
aquisitor_DSP_eth_2011_424J600.JPG (204.44 KiB) Viewed 4359 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: ENC424J600

#5 Post by filip » 03 Apr 2012 14:31

Hi,

Which example exactly were you trying to compile ?
Which compiler version are you using ?

Regards,
Filip.

fzanoto
Posts: 225
Joined: 25 Jul 2006 13:53

Re: ENC424J600

#6 Post by fzanoto » 03 Apr 2012 17:09

mikrobasic pro for DSPIC 5.4

I can compile now :
Spi_Ethernet_24j600_Init(myMacAddr, myIpAddr, _SPI_Ethernet_24j600_AUTO_NEGOTIATION)


but the hardware don´t work !!

see code:

Code: Select all

program aquisitor_002_2012

dim myMacAddr as byte[6]   ' my MAC address
    myIpAddr  as byte[4]   ' my IP address
    gwIpAddr  as byte[4]
    dnsIpAddr as byte[4]
    ipMask    as byte[4]
    IpAddr    as byte[4]

    canais as byte
    localport, kk, ad, i, jj, sample_rate, tempo, pwm_period1, duty as word
    lixo as longint
    flag_pronto as bit

    _pc  as byte[10]
    dados_pic as byte[1400]
  
  Spi_Ethernet_24j600_Rst as sbit at RF1_bit
  Spi_Ethernet_24j600_CS  as sbit at RF0_bit
  Spi_Ethernet_24j600_Rst_Direction as sbit at TRISF1_bit
  Spi_Ethernet_24j600_CS_Direction  as sbit at TRISF0_bit


 ' SPI_Ethernet_Rst as sbit at LATF1_bit
 ' SPI_Ethernet_CS  as sbit at LATF0_bit
 ' SPI_Ethernet_Rst_Direction as sbit at TRISF1_bit
  'SPI_Ethernet_CS_Direction  as sbit at TRISF0_bit

'------------------------------------------------------------
sub procedure le_1_canal

ad = ADC1_Get_Sample(1)

  dados_pic[jj]=hi(ad)
  dados_pic[jj+1]=lo(ad)


end sub
'------------------------------------------------------------
sub procedure le_2_canais

ad = ADC1_Get_Sample(1)

  dados_pic[jj]=hi(ad)
  dados_pic[jj+1]=lo(ad)

ad = ADC1_Get_Sample(2)


  dados_pic[jj+2]=hi(ad)
  dados_pic[jj+3]=lo(ad)


end sub
'------------------------------------------------------------
sub procedure le_3_canais

ad = ADC1_Get_Sample(1)

  dados_pic[jj]=hi(ad)
  dados_pic[jj+1]=lo(ad)

ad = ADC1_Get_Sample(2)


  dados_pic[jj+2]=hi(ad)
  dados_pic[jj+3]=lo(ad)

ad = ADC1_Get_Sample(4)

  dados_pic[jj+4]=hi(ad)
  dados_pic[jj+5]=lo(ad)


end sub

'------------------------------------------------------------
sub procedure le_4_canais

ad = ADC1_Get_Sample(1)

  dados_pic[jj]=hi(ad)
  dados_pic[jj+1]=lo(ad)

ad = ADC1_Get_Sample(2)


  dados_pic[jj+2]=hi(ad)
  dados_pic[jj+3]=lo(ad)

ad = ADC1_Get_Sample(4)

  dados_pic[jj+4]=hi(ad)
  dados_pic[jj+5]=lo(ad)

ad = ADC1_Get_Sample(6)

  dados_pic[jj+6]=hi(ad)
  dados_pic[jj+7]=lo(ad)


end sub
'----------------------------------------------
sub procedure seta_interrupt_externa
IEC0 = 1   'Interrupt is set on a rising edge
IFS0 = 0       'interrupt flag cleared

end sub

'-----------------------------------------------------------------------
'sub function Spi_Ethernet_UserTCP(dim byref remoteHost as byte[4],
 '                             dim remotePort, localPort, reqLength as word, dim byref flags as TEthPktFlags) as word
sub function SPI_Ethernet_24j600_UserTCP(dim byref remoteHost as byte[4],
                                  dim remotePort as word,
                                  dim localPort as word,
                                  dim reqLength as word,
                                  dim byref flags as TEthj600PktFlags) as word



  if(remoteport <> 10001) or (reqlength > 10) then            ' I listen only to web request on port 80
    result = 0
    exit
  end if

  IpAddr[0] = remoteHost[0]
  IpAddr[1] = remoteHost[1]
  IpAddr[2] = remoteHost[2]
  IpAddr[3] = remoteHost[3]

 for i = 0 to 9
  _pc[i] = SPI_Ethernet_24j600_getByte()
    SPI_Ethernet_24j600_putByte(_pc[i])

 next i

 canais = _pc[1]
hi(sample_rate) = _pc[2]
lo(sample_rate) = _pc[3]

jj = 0

  result = 10

end sub

'-----------------------------------------------
'sub function Spi_Ethernet_UserUDP(dim byref remoteHost as byte[4],
  '                            dim remotePort, destPort, reqLength as word, dim byref flags as TEthPktFlags) as word


sub function SPI_Ethernet_24j600_UserUDP(dim byref remoteHost as byte[4],
                              dim remotePort as word,
                              dim destPort as word,
                              dim reqLength as word,
                              dim byref flags as TEthJ600PktFlags) as word


  if(remoteport <> 10001) or (reqlength > 10) then            ' I listen only to web request on port 80
    result = 0
    exit
  end if

  IpAddr[0] = remoteHost[0]
  IpAddr[1] = remoteHost[1]
  IpAddr[2] = remoteHost[2]
  IpAddr[3] = remoteHost[3]

 for i = 0 to 9
    _pc[i] = SPI_Ethernet_24j600_getByte()
       SPI_Ethernet_24j600_putByte(_pc[i])

 next i
 
 if _pc[0] <> 204 then  'garante protocolo
 result = 0
 exit
 end if
 
 if _pc[4] = 255 then  'reseta caso trave
 reset()
 end if

 canais = _pc[1]
hi(sample_rate) = _pc[2]
lo(sample_rate) = _pc[3]

jj = 0

  result = 10

end sub
'-----------------------------------------------
sub procedure verifica
   select case canais

       case 1
       le_1_canal
       jj = jj + 2

       case 2
       le_2_canais
       jj = jj + 4

       case 3
       le_3_canais
       jj = jj + 6

       case 4
       le_4_canais
       jj = jj + 8

       case else
       le_4_canais
       jj = jj + 8

   end select
end sub
'---------------------------------------------------
sub procedure envia_pacote

'SPI_Ethernet_sendUDP(IpAddr, 10001, 10001, @dados_pic, 1392)

SPI_Ethernet_24j600_sendUDP(IpAddr, 10001, 10001, @dados_pic, 1392)


end sub
'-----------------------------------------------

sub procedure interrupt() iv IVT_ADDR_INT0INTERRUPT

 ifs0.0 = 0    'zera flag interrupt externa
 IEC0 = 0   'desliga interrupt para não dar reentrada
verifica  'e le aD  e incrementa jj

portd.3 = not(portd.3) 'gera clock

 ifs0.0 = 0    'zera flag interrupt externa
 IEC0 = 1

end sub
'-----------------------------------------------------
main:

  trisa.11 = 1        'interrupt externa
  trisb = 0xFFFF     ' Use PORTB for input signal
  portb = 0
  trisd.3 = 0
  portd.3 = 0
  trisf = %0000000000000100
  portf = 0

sample_rate = 3000  'sample rate inicial
duty = 4000 - (sample_rate/3)
pwm_period1 = sample_rate
PWM_Init(pwm_period1 , 1, 1, 2) '(portd.0 - OC1)
PWM_Start(1)
PWM_Set_Duty(duty,  1)

  ' set mac address
  myMacAddr[0] = 0x08
  myMacAddr[1] = 0x12
  myMacAddr[2] = 0x20
  myMacAddr[3] = 0x11
  myMacAddr[4] = 0x10
  myMacAddr[5] = 0x33

  myIpAddr[0] = 10
  myIpAddr[1] = 0
  myIpAddr[2] = 0
  myIpAddr[3] = 178

    ' set gateway address
  gwIpAddr[0]  = 10
  gwIpAddr[1]  = 0
  gwIpAddr[2]  = 0
  gwIpAddr[3]  = 138

  ' set dns address
  dnsIpAddr[0] = 10
  dnsIpAddr[1] = 0
  dnsIpAddr[2] = 0
  dnsIpAddr[3] = 138

  ' set subnet mask
  ipMask[0]    = 255
  ipMask[1]    = 255
  ipMask[2]    = 255
  ipMask[3]    = 0

  IpAddr[0] = 10
  IpAddr[1] = 0
  IpAddr[2] = 0
  IpAddr[3] = 8

  delay_ms(5)     'espera enc iniciar

SPI1_Init()
Spi_Ethernet_24j600_Init(myMacAddr, myIpAddr, _SPI_Ethernet_24j600_AUTO_NEGOTIATION)

 ' SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_2, _SPI_PRESCALE_PRI_1,
  '                   _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE)
 ' SPI_Ethernet_Init(myMacAddr, myIpAddr, _SPI_Ethernet_FULLDUPLEX)              ' init ethernet module
 ' SPI_Ethernet_setUserHandlers(@SPI_Ethernet_UserTCP, @SPI_Ethernet_UserUDP)    ' set user handlers
 SPI_Ethernet_24j600_setUserHandlers(@SPI_Ethernet_24j600_UserTCP, @SPI_Ethernet_24j600_UserUDP)


  ' dhcp will not be used here, so use preconfigured addresses
 ' SPI_Ethernet_confNetwork(ipMask, gwIpAddr, dnsIpAddr)
 SPI_Ethernet_24j600_confNetwork(ipMask, gwIpAddr, dnsIpAddr)

ADC1_Init()
ADCON2.13 = 1     'vref externo 12bit´s
ADCON2.14 = 0
ADCON2.15 = 0
ADCSSL  = 0        'no input scan

  canais = 4   'quantidade de canais

for jj = 0 to 1391  'zera memoria inicialmente
dados_pic[jj] = 0
next jj

jj = 0

 seta_interrupt_externa

'-----------------------------------------------------------------------
  while TRUE
  ' SPI_Ethernet_doPacket()    ' process incoming Ethernet packets
    SPI_Ethernet_24j600_doPacket()
 
 
if jj > 1391 then
jj = 0
envia_pacote
end if

if (sample_rate) <> pwm_period1 then
IFS0 = 0
IEC0 = 0  'desliga interrupt externa
pwm_period1 = sample_rate
duty = 4000 - (sample_rate/3)
PWM_Init(pwm_period1 , 1, 1, 2) '(portd.0 - OC1)
PWM_Start(1)
PWM_Set_Duty(duty,  1)
IEC0 = 1 'liga interrupt externa
end if

  wend

end.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: ENC424J600

#7 Post by filip » 04 Apr 2012 10:08

Hi,

Please, could you try the original dsPIC example for Serial Ethernet 2 from the following link :
http://www.mikroe.com/eng/products/view ... t-2-board/

Your have pasted a custom code, and unfortunately the scope of the Technical Support doesn't cover debugging this kind of codes.
Thank you for the understanding.

Regards,
Filip.

fzanoto
Posts: 225
Joined: 25 Jul 2006 13:53

Re: ENC424J600

#8 Post by fzanoto » 04 Apr 2012 15:10

Hi,
I try your code in my hardware, but don´t work !!
I believe the problem is in my hardware !!

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: ENC424J600

#9 Post by filip » 05 Apr 2012 10:04

Hi,

I can guarantee that this code works with our Serial Ethernet 2 board.
If you are using your own hardware, then maybe it is not working correctly.

Please understand that the scope of the Support department does not cover debugging custom hardware.

Regards,
Filip.

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”