Getting started with Arduino and WIZ820io

(Difference between revisions)
Jump to: navigation, search
Line 27: Line 27:
 
#Flash the bootloader to Atmega328P
 
#Flash the bootloader to Atmega328P
  
[[File:Avr sdudio 6 fuse bits bootloader.PNG|frame|center|600x600px]]
+
[[File:Avr sdudio 6 fuse bits bootloader.PNG|frame|center|600x600px|Avr sdudio 6 fuse bits bootloader.PNG]]
  
  
Line 39: Line 39:
  
  
[[File:Avr sdudio 6 fuse bits bootloader flash.PNG|frame|center|600x600px|Avr sdudio 6 fuse bits bootloader flash.PNG]]
+
[[File:Avr sdudio 6 fuse bits bootloader flash.PNG|frame|center|600x600px]]
  
  
Line 316: Line 316:
 
== First Test Hardware<br/> ==
 
== First Test Hardware<br/> ==
  
[[File:Wiz820io first test.jpg|border|center]]<br/><source lang="bascomavr">
+
[[File:Wiz820io first test.jpg|border|none|800x800px|Wiz820io first test.jpg]]<br/><source lang="bascomavr">
 
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
 
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
 
Spiinit
 
Spiinit

Revision as of 21:17, 17 February 2013

Back to MCS WIKI Main entry

Contents


Getting started with Arduino and WIZ820io

Used Hardware:

To get started an Arduino Duemilanove board is used with an Arduino prototyping shield and prototyping jump wires.

To get the 3.3V for the WIZ820io power supply an voltage regulator is needed to transform the 5V from the Arduino board to 3.3V.

(The maximum current draw from FTDI chip on the Arduino Duemilanove is max. 50mA and therefore not usable to power the WIZ820io)

Used Boot loader:

You can use the Arduino boot loader but in this example an AVRISP MKII is used to flash an Bascom-AVR Bootloader.

For this you need an AVRISP MKII and AVR Studio to flash the bootloader on the Atmega328P on the Arduino.


Steps:

  1. Open AVR Studio 6
  2. Hit Tools >>> Device Programming
  3. Select AVRISP mkII under Tools and Select ATMEGA328P under devices and hit Apply button
  4. Check the BOORST fuse bit (see picture below)
  5. Flash the bootloader to Atmega328P
Avr sdudio 6 fuse bits bootloader.PNG


How to flash the bootloader:

  1. Goto Memories
  2. Select the Bootloader HEX file
  3. Hit the Program button


Avr sdudio 6 fuse bits bootloader flash.PNG


Following you can find the Bootloader written in Bascom-AVR which works with baud rate of 57600baud:

$crystal = 16000000 'Arduino is running at 16MHz
$baud = 57600 '57600 Baud
$timeout = 900000
 
$regfile = "m328pdef.dat"
$loader = $3c00 'sets the bootsize to 1024 words under flash size
Const Pagemsb = 6 '64 words in a page reguires 6 bits
 
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
 
Dim Retries As Byte
Dim Receivedbyte As Byte
Dim Kindofdata As Byte
Dim Spmcsrvalue As Byte
Dim Calculatedchecksum As Byte
Dim Receivedblock As Byte
Dim Countedblock As Byte
Dim Invertedblock As Byte
Dim Receivedchecksum As Byte
Dim Receivedbytes(128) As Byte
Dim J As Byte
Dim Vl As Byte
Dim Vh As Byte
Dim Wrd As Word
Dim Page As Word
Dim Z As Long
 
Disable Interrupts
 
Const Maxword =(2 ^ Pagemsb) * 2
Const Zpagemsb = Pagemsb + 1
Const Soh = &H01
Const Stx = &H02
Const Eot = &H04
Const Ack = &H06
Const Nak = &H15
Const Can = &H18
 
Retries = 5
Testformagicbyte:
Receivedbyte = Waitkey()
Print Chr(receivedbyte);
If Receivedbyte = 123 Then
 Kindofdata = 0
 Goto Loader
Elseif Receivedbyte = 124 Then
 Kindofdata = 1
 Goto Loader
Elseif Receivedbyte <> 0 Then
 Decr Retries
 If Retries <> 0 Then Goto Testformagicbyte
End If
Goto _reset
 
Loader:
Do
 Receivedbyte = Waitkey()
Loop Until Receivedbyte = 0
 
If Kindofdata = 0 Then
 Spmcsrvalue = 3 : Gosub Do_spm
 Spmcsrvalue = 17 : Gosub Do_spm
End If
Retries = 10
 
Do
 Calculatedchecksum = 0
 Print Chr(nak);
 Do
 Receivedbyte = Waitkey()
 Select Case Receivedbyte
 Case &H01: '<SOH>
 Incr Countedblock
 Calculatedchecksum = 1
 Receivedblock = Waitkey()
 Calculatedchecksum = Calculatedchecksum + Receivedblock
 Invertedblock = Waitkey()
 Calculatedchecksum = Calculatedchecksum + Invertedblock
 For J = 1 To 128
 Receivedbytes(j) = Waitkey()
 Calculatedchecksum = Calculatedchecksum + Receivedbytes(j)
 Next
 Receivedchecksum = Waitkey()
 If Countedblock = Receivedblock Then
 If Receivedchecksum = Calculatedchecksum Then
 Gosub Writepage
 Print Chr(ack);
 Else
 Print Chr(nak);
 End If
 Else
 Print Chr(nak);
 End If
 Case &H04: '<EOT>
 If Wrd > 0 And Kindofdata = 0 Then
 Wrd = 0
 Spmcsrvalue = 5 : Gosub Do_spm
 Spmcsrvalue = 17 : Gosub Do_spm
 End If
 Print Chr(ack);
 Waitms 20
 Goto _reset
 Case &H18: '<CAN>
 Goto _reset
 Case Else
 Exit Do
 End Select
 Loop
 
 If Retries > 0 Then
 Waitms 1000
 Decr Retries
 Else
 Goto _reset
 End If
Loop
 
Writepage:
If Kindofdata = 0 Then
 For J = 1 To 128 Step 2
 Vl = Receivedbytes(j)
 Vh = Receivedbytes(j + 1)
 lds r0, {vl}
 lds r1, {vh}
 Spmcsrvalue = 1 : Gosub Do_spm
 Wrd = Wrd + 2
 If Wrd = Maxword Then
 Wrd = 0
 Spmcsrvalue = 5 : Gosub Do_spm
 Spmcsrvalue = 17 : Gosub Do_spm
 Page = Page + 1
 Spmcsrvalue = 3 : Gosub Do_spm
 Spmcsrvalue = 17 : Gosub Do_spm
 End If
 Next
Else
 For J = 1 To 128
 Writeeeprom Receivedbytes(j) , Wrd
 Wrd = Wrd + 1
 Next
End If
Return
 
Do_spm:
 Bitwait Spmcsr.0 , Reset
 Bitwait Eecr.1 , Reset
 Z = Page
 Shift Z , Left , Zpagemsb
 Z = Z + Wrd
 lds r30, {Z}
 lds r31, {Z + 1}
 #if _romsize > 65536
 lds r24, {Z + 2}
 sts rampz, r24
 #endif
 Spmcsr = Spmcsrvalue
 spm
 nop
 nop
Return


First "Hello World" Program:

Next Step is to flash a first Hello World program direct with Bascom-AVR:

 

  1. Goto Options >>> Programmer in Bascom-AVR
  2. Select MCS Bootloader
  3. Select the com port of Arduino (in this case com3) and baud rate = 57600 (the same as in the bootloader program)
  4. Write the first Hello World program
Arduino bootloader settings in bascom avr.PNG


Source code for Hello World program:


$regfile = "m328pdef.dat"
$crystal = 16000000 '16MHz
$hwstack = 60
$swstack = 60
$framesize = 60
 
Config Com1 = 57600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
 
 
Do
 
 Print "Hello World"
 Waitms 1000
 
Loop
 
 
End 'end program

Just compile this Hello World program and hit the Program Chip button or use shortcut F4 in Bascom-AVR (the programmer should be already configured before).


Then open an terminal program of your choice and connect with 57600 baud on the Arduino interface number (in this case COM3) and you will notice the

Hello World messages coming in.


Hardware Connections for WIZ820io

HARDWARE CONNECTIONS:


WIZ820io
Arduino
GND
GND
MISO
MISO
MOSI
MOSI
SCK
SCK
nSS
Portd.7
nReset
Portb.2
PWDN

GND

3.3V (over additional voltage regulator)
5V input for additional voltage regulator
nINT
not connected


SPI and TCPIP Configuration for WIZ820io

At first we need to configure the SPI interface and initialize the SPI interface. Then we need a defined Reset of the WIZ820io before we configure the TCPIP Interface. Needed infos are:

  • We use noint. This is the preferred method.
  • MAC address of WIZ820io
  • IP address of WIZ820io
  • Subnet Mask
  • Gateway (e.g. Router adress)
  • Local Port
  • Chip is here W5200 which is used in the WIZ820io module
  • SPI = 1. THe W5200 chip is connected with SPI.
  • Chip select is connected with Portd.7

First Test Hardware

Wiz820io first test.jpg

Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
Spiinit
 
Config Pinb.2 = Output
W5200_nreset Alias Portb.2
Reset W5200_nreset
Waitms 1
Set W5200_nreset
Waitms 250
 
 
Enable Interrupts
 
 'Here you need MAC address, the ip address you like to use, subnet mask, gateway and localport
 Config Tcpip = Noint , _
 Mac = 0.1.94.127.1.255 , _
 Ip = 192.168.2.254 , _
 Submask = 255.255.255.0 , _
 Gateway = 192.168.2.1 , _
 Localport = 1000 , _
 Chip = W5200 , _
 Spi = 1 , _
 Cs = Portd.7
Back to MCS WIKI Main entry
Personal tools
Namespaces
Variants
Actions
Navigation
Language