Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Build a Webserver with ENC28J60 +AVR
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog
View previous topic :: View next topic  
Author Message
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Dec 13, 2011 4:13 am    Post subject: Reply with quote

Just for a demonstration of what you can do with the server and iframes I have changed the main page to open as 6 main menus and you can make even more if you chose index in the menu, another 6 open in that iframe (just like rabbits) if you chose some of the other options like server settings you can see how they can work really well. Note: This is only to demo the iframes I will re-do the pages to make it work nicely (not like rabbits).

Have fun

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Wed Dec 28, 2011 9:22 am    Post subject: Reply with quote

Ok been busy Xmas and all.

Now I wanted to be able to set the baud rate of the serial ports from a variable stored in EEPROM but there is not a command to do that so I had to write a little Sub to do this by setting the registers so I thought I would share it.

It will be in the next lot of code but I thought it might be helpfull to have it on its own for others.

Code:


Const Xtal = 8000000                                        'This is the crystal frequency
Dim Lxtl As Long
Dim Uhxtl As Byte At Lxtl + 1 Overlay


'-------------------------------------------
 '---set baud rate for serial port and only allow valid setting
 '-------------------------------------------------
Sub Setbaud

Local Lv As Long
Local Lw As Byte
Local Lx As Byte
Local Ly As Byte
Local Lz As Byte


Ly = Bord(1)                                                'from eeprom
Lz = Bord(2)                                                'Bord(2) is an eeprom array of 2


Lw = Ly

    For Lx = 1 To 2

        Select Case Lw

           Case 1

             Lv = 110

           Case 2

             Lv = 300

           Case 3

             Lv = 1200

           Case 4

             Lv = 2400

           Case 5

             Lv = 4800

           Case 6

             Lv = 9600

           Case 7

             Lv = 19200

           Case 8

             Lv = 38400

           Case 9

             Lv = 57600

           Case 10

             Lv = 115200

           Case 11

             Lv = 230400

           Case 12

             Lv = 460800

           Case 13

             Lv = 921600

        End Select


        Select Case Lx

            Case 1

              Lxtl = Xtal / Lv                              ' divide crystal freq. by the wanted baud rate
                                                            'Xtal = crystal frequency
               Lxtl = Lxtl / 16                             'divide the result by 16
               Lxtl = Lxtl - 1                              'and subtract 1
               Ubrr0l = Lxtl                                'when you assign a long it will only write the BYTE
               Ubrr0h = Uhxtl                               'we use an overlayed variable that is the high byte

            Case 2

             Lxtl = Xtal / Lv                               ' divide crystal freq. by the wanted baud rate
                                                            'Xtal = crystal frequency
               Lxtl = Lxtl / 16                             'divide the result by 16
               Lxtl = Lxtl - 1                              'and subtract 1
               Ubrr1l = Lxtl                                'when you assign a long it will only write the BYTE
               Ubrr1h = Uhxtl                               'we use an overlayed variable that is the high byte
        End Select

        Lw = Lz

    Next Lx

End Sub
 
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Jan 08, 2012 5:01 am    Post subject: Test posting Reply with quote

Having trouble making a post!
Back to top
View user's profile
mfulde

Bascom Member



Joined: 24 Apr 2007
Posts: 21
Location: Lonsee, Germany

germany.gif
PostPosted: Sun Jan 08, 2012 6:28 pm    Post subject: Sub Enc28j60readbuffer(pcktlen As Word) Reply with quote

Hi Paul,

thanks for this project and this blog, you did a very nice job! Thanks!

I have a question related your code and Ben's tutorial about BASCOM-AVR to drive an AVR and an EathernetController ENC28J60. I'm not shure if this is the correct Thread placing my question, but I will try...

For a better understanding what happens in BASCOM and in the ENC28J60 I’m using Ben's tutorial to follow step by step your implementation.
Currently I’m able to send a ARP message and receive data from the router. It looks very well … But it's very hard for me to understand.

But …. now I’m helpless because I don’t understand the Enc28j60readbuffer function.

Sub Enc28j60readbuffer(pcktlen As Word)
Enc28j60_cs = 0
Spdr = &H3A
Do
Loop Until Spsr.spif = 1
Spdr = &HFF 'dummy byte
Do
Loop Until Spsr.spif = 1
Buffer(1) = Spdr
Buffer(1) = Spdr

If Pcktlen > 1 Then
For X = 1 To Pcktlen
Spdr = &HFF 'dummy byte
Buffer(x) = Spdr
'Print Hex(buffer(x)) ; " " ; X
Next X
End If
Enc28j60_cs = 1
End Sub

Please please please explain my why you read out the SPDR register into Buffer(1) for twice a time (marked in red). Is it related to timing issues because if I print the variable values out I can see the same value. Hmmmmm, I don’t understand this.
I want to understand how the program works to be able and implement my own first project with Ethernet.

Thanks beforehand,
Kind regards from Germany,

Markus

_________________
MaFu
Back to top
View user's profile Visit poster's website
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Sun Jan 08, 2012 7:17 pm    Post subject: Must be a typo... Reply with quote

Markus, I checked. Think it is a typo. But this routine is combined with another routine in Step 24 and later in the tutorial.

And indeed, PaulVK is doing a GREAT job!

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
mfulde

Bascom Member



Joined: 24 Apr 2007
Posts: 21
Location: Lonsee, Germany

germany.gif
PostPosted: Sun Jan 08, 2012 7:35 pm    Post subject: Reply with quote

Hi Ben,

thanks for your fast answer and your help!

Yes, I saw that two routines are combined in step 24 and in the one-and-only routine I can't find a register acces twice. So I'm wondering but now it's clear for me Very Happy

Have a nice week,
Markus

_________________
MaFu
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Jan 09, 2012 10:15 am    Post subject: Reply with quote

Ok this is to test posting to forum.

I have changed all the language to interact with the user to constants so that to change the language used in the server all that is needed is to change an include file so I will be naming my one english.inc and I invite others to translate it and up load it in the same format eg dutch dutch.inc , german german.inc also any additions are also welcome as I may have missed something.

In the above posted code there are these additions

RS232 speed can be changed via the serial command line

Two iframes for the first (Main page) & no headers on the others

More settings in eeprom
Speed of serial port stored and set on start up

Settings for analog (ADC) ports stored, multiplier, min max(for alarm), reference voltage, + & - scale value for use with graphs ect, two spare for future use

Type of conversion for each ADC storded in eeprom eg average of multiple readings or multiple readings and shift right used. Up to you what you add to the sub that reads the ADC port

Names of digital and analog ports to be set by user

Two lots of four for analog inputs, two lots of four for digital inputs both will now be generated by one page this also reduced the flash use by 10%

Also note I am using a M644 at the moment the M644P went faulty (maybe I wore it out!) still seems to work ok with M644 though. I also still have spare ram left but it is slowly dropping!


Still a lot more I want to add & finish but it may just fit into the M644 the code has been stitting between 60 & 70% going up and down as I find ways to re-use things like web pages.

Regards Paul

since that worked I added a new lot of code


Last edited by Paulvk on Mon Jan 09, 2012 10:52 pm; edited 4 times in total
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Jan 09, 2012 10:56 am    Post subject: Reply with quote

Here are the constants as an .inc file

Thankyou Ben !!

After this is done I am going to try and move it to the WIZ200WEB as well Laughing


PS this is a board that would make it easy to run this code http://futurlec.com/Mini_Ethernet.shtml , this should also run the code with some changes (see Bens home page for one he used) http://www.lochraster.org/etherrape/?en
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sat Jan 28, 2012 1:12 am    Post subject: Things You Should Know About The ENC28J60 Reply with quote

There are a number of things about this device that need to be known when designing the circuit but unfortunately they are not all in the data sheet and as I keep finding out more all the time I will probably add to this list!

1. The SPI clock should be above 8Mhz or both come from the same clock or you should get the micro controller clock from the ENC28J60.

2. It can be driven by a 5V powered micro controller but its outputs to that micro controller will be 2.6V so the micro controller must be able to see 2.6V as a HI or logic one Note most AVRs are ok up to 4.5V supply, 5V is border line by the graph in the data sheets!

3. The bias resistor on the ENC28J60 has 2 values, one for up to revision 4 (2.7K), another (3.23K) after this but you have to read the version number in the chip to find out as its not on the outside!

4. It can have problems with under run & over run on the SPI port the solution is to fit series resistors in these lines of a value of 100 to 300 ohms, microchip uses 180 ohms in their boards so why not do the same! Now maybe something to keep in mind when using SPI !


5. There are a number of problems with the device itself so get all the errata sheets and read them for the work arounds. One I have just come across is that the transmit buffer should be at the end of the internal ram you should put the receive buffer at H0000 the start of the ram.

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Wed Feb 01, 2012 6:41 am    Post subject: Reply with quote

Have been working on more IFrame pages and have come up with this one to display 16 inputs or outputs with buttons to change them there are a total of six pages being displayed. The table at the top is to put hyper links back to other pages the four IFrames can hold other pages as this is a dynamic page with four IFrames in it that can be chosen by the program.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Wed Feb 01, 2012 7:16 am    Post subject: Reply with quote

Here are some more screen shots of the generated pages.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Feb 05, 2012 1:06 pm    Post subject: Reply with quote

Have been busy compacting some of the HTML I have now managed to get a page with 8 outputs/inputs with a label next to them into one packet of around 1200 bytes. I have now also got this working with two 74HC595s to give 16 digital outputs each which can be turned off/on at the press of a button, the buttons change colour in response to the value of the bits in the variable that stores the state of the outputs and the word OFF ON changes also, these are constants so they can be changed. With the Iframes I display 2 pages giving the whole 16 outputs. The outputs can also be changed by sending a command to the server you can send as many at one time as you want so all 16 could be changed in one command group. I have not much ram left now 197 bytes I have also reduced and remove some variables to free some up. I have gone back to a mega644p as I am running off the clock from the ENC28J60 at 12.5mhz, I have also set the double speed bit on the SPI port to bring the clock to 6.25Mhz.

The program is now 6671 lines including space between lines with 52 sub routines and compiles to 49794 bytes so I still have space left

Note have added some more constants

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Feb 06, 2012 12:35 pm    Post subject: Reply with quote

Have added more commands the list thus far for TCPIP

All groups are preceded with /? eg /?LCD1=BGF&LCD2=KJH NOTE the & is to group same type commands

LCD1=XYZ send XYZ to line one on LCD

LCD2=ABC send ABC to line one on LCD

DIOPxx=1 turn digital output on replace xx with 01-16
DIOPxx=0 turn it off

PRINT1=JKL send JKL to serial port one

PRINT2=JKL send JKL to serial port two (not fully implemented as I have only one at present)

These can all be sent by a webpage or from the menus and sent directly by another program/computer as a GET type request.

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Feb 14, 2012 5:23 am    Post subject: Reply with quote

Here is a diagram of the proto-type I am using which I made myself.
The 74HC595, 74HC165 & the DS1307 are on separate boards, the sd card is not yet installed. The 25AA02E48 is a special case as it comes with a unique MAC number stored on it from microchip but does not have to be used.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sat Feb 18, 2012 7:28 am    Post subject: Reply with quote

I have nearly all the pages working to change all the various things stored in eeprom working, this is a lot of pages approaching 50. So we have all these pages and still only used 88% of flash & 146 bytes of ram left. I needed another page for inputs but with a drop down list instead of an input box, I did not want to take up flash by re-creating another page when all I needed to do was to change the bottom half of the page so what to do? Well what I did was use one of the CHANGE data lines to move the read pointer to another set of data and then change the page number to another one that is 100 more so as to make it easy to see. Now not only are the pages dynamic but we can cut & paste forms from parts. This means if you make a set of building blocks for your forms you can put these together to get the form you want.

You can see this in Htmlpage case CHANGE08 in the code below.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum