Getting started with Arduino and WIZ820io
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 | + | [[File:Avr sdudio 6 fuse bits bootloader flash.PNG|frame|center|600x600px]] |
Line 258: | Line 258: | ||
+ | |||
+ | == Hardware Connections for WIZ820io<br/> == | ||
+ | |||
+ | HARDWARE CONNECTIONS: | ||
+ | |||
+ | |||
+ | |||
+ | {| border="1" cellpadding="1" cellspacing="1" height="179" width="500" | ||
+ | |- | ||
+ | | style="text-align: center" | '''WIZ820io<br/>''' | ||
+ | | style="text-align: center" | '''Arduino<br/>''' | ||
+ | |- | ||
+ | | style="text-align: center" | GND<br/> | ||
+ | | style="text-align: center" | GND<br/> | ||
+ | |- | ||
+ | | style="text-align: center" | MISO<br/> | ||
+ | | style="text-align: center" | MISO<br/> | ||
+ | |- | ||
+ | | style="text-align: center" | MOSI<br/> | ||
+ | | style="text-align: center" | MOSI<br/> | ||
+ | |- | ||
+ | | style="text-align: center" | SCK<br/> | ||
+ | | style="text-align: center" | SCK<br/> | ||
+ | |- | ||
+ | | style="text-align: center" | nSS<br/> | ||
+ | | style="text-align: center" | Portd.7<br/> | ||
+ | |- | ||
+ | | style="text-align: center" | nReset<br/> | ||
+ | | style="text-align: center" | Portb.2<br/> | ||
+ | |- | ||
+ | | style="text-align: center" | PWDN<br/> | ||
+ | | style="text-align: center" | <p style="text-align: center">GND</p> | ||
+ | |- | ||
+ | | style="text-align: center" | 3.3V (over additional voltage regulator)<br/> | ||
+ | | style="text-align: center" | 5V input for additional voltage regulator<br/> | ||
+ | |- | ||
+ | | style="text-align: center" | nINT<br/> | ||
+ | | style="text-align: center" | not connected<br/> | ||
+ | |} | ||
+ | |||
+ | <br/><br/> | ||
Back to [http://wiki.mcselec.com/MCS_Wiki_Main_entry MCS WIKI Main entry] | Back to [http://wiki.mcselec.com/MCS_Wiki_Main_entry MCS WIKI Main entry] |
Revision as of 20:48, 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 Bootloader:
You can use the Arduino bootloader 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:
- Open AVR Studio 6
- Hit Tools >>> Device Programming
- Select AVRISP mkII under Tools and Select ATMEGA328P under devices and hit Apply button
- Check the BOORST fuse bit (see picture below)
- Flash the bootloader to Atmega328P
How to flash the bootloader:
- Goto Memories
- Select the Bootloader HEX file
- Hit the Program button
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:
- Goto Options >>> Programmer in Bascom-AVR
- Select MCS Bootloader
- Select the com port of Arduino (in this case com3) and baud rate = 57600 (the same as in the bootloader program)
- Write the first Hello World program
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 |
Back to MCS WIKI Main entry