Closed vmayoral closed 8 years ago
1- In C:\Users\xUser\Documents\Arduino\hardware create a folder with the name: breadbord 2- Inside breadbord folder create another folder called avr. 3- Inside avr folder create the bootloaders folder and the next boards.txt:
##############################################################
openservo.name=OpenServo
openservo.upload.protocol=arduino
atmeopenservoga328bb.upload.maximum_size=30720
openservo.upload.speed=57600
openservo.bootloader.low_fuses=0xFF //Important to be able to conect external 20Mhz resonator
openservo.bootloader.high_fuses=0xD8 //Last 8 important to configure BootLoaderSection of 4KB
openservo.bootloader.extended_fuses=0x05
openservo.bootloader.file=atmega/OSBootloader.hex //Where the .hex file is save.
openservo.bootloader.unlock_bits=0x3F
openservo.bootloader.lock_bits=0x0F
openservo.build.mcu=atmega328
openservo.build.f_cpu=20000000L //Frecuency of the resonator
openservo.build.core=arduino:arduino
openservo.build.variant=arduino:standard
openservo.bootloader.tool=arduino:avrdude
openservo.upload.tool=arduino:avrdude
openservo.build.board=AVR_Openservo
4.- Inside bootloaders create an atmega folder and there put the OSBootloader.hex 5.- After we have done the 1 to 4 steps if we open Arduino we will have our board ready:
6.- If there are problems programming the bootloader we can change the C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdud.conf file
Useful reference links: https://www.arduino.cc/en/Tutorial/ArduinoISP https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard http://forum.arduino.cc/index.php/topic,51819.0.html
First we start wiring like the left image but we had problems when we burn the bootloader:
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.
After we assemble the right image but instead of using the 16MHz resonator we use the 20MHz resonator as we speficy in the board.txt. Also we use two 22pF condensator used to help the resonator to oscillated and a 10K resistance.
1- Connect the Arduino Uno through the USB cable. 2- In the IDE go to Tools and select the Arduino Uno board, the COM port and the programmer AVR ISP. 3- Open ArduinoISP from File>Examples>11. ArduinoISP 4- Upload the sketch to Arduino Uno board. 5- We disconnect the USB from the Arduino Uno since the flash is programmed and we wire like the right image. 6- When we finish connecting all the wires connect the USB cable to our Arduino Uno. 7- In the IDE we set the Board to OpenServo, and the Programmer: Arduino as ISP 8- Click in Tools> Burn Bootloader. 9- If everything is OK the and if we have compliation and upload checked in File>Preferences. We will see the next lines.
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9514
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "C:\Users\Jorge\Documents\Arduino\hardware\breadboard_jorge\avr/bootloaders/atmega/OSBootloader.hex"
avrdude: writing flash (930 bytes):
Writing | ################################################## | 100% 1.12s
avrdude: 930 bytes of flash written
avrdude: verifying flash memory against C:\Users\Jorge\Documents\Arduino\hardware\breadboard_jorge\avr/bootloaders/atmega/OSBootloader.hex:
avrdude: load data flash data from input file C:\Users\Jorge\Documents\Arduino\hardware\breadboard_jorge\avr/bootloaders/atmega/OSBootloader.hex:
avrdude: input file C:\Users\Jorge\Documents\Arduino\hardware\breadboard_jorge\avr/bootloaders/atmega/OSBootloader.hex contains 930 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.63s
avrdude: verifying ...
avrdude: 930 bytes of flash verified
avrdude: reading input file "0x0F"
avrdude: writing lock (1 bytes):
Writing | ################################################## | 100% 0.02s
avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x0F:
avrdude: load data lock data from input file 0x0F:
avrdude: input file 0x0F contains 1 bytes
avrdude: reading on-chip lock data:
Reading | ################################################## | 100% 0.01s
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude done. Thank you.
10- The next step will be to set the USB to I2C connection and probe it!
We might need a programmer to be able to include the program in the microcontroller. In case we aren't capable of doing it with the arduino as a ISP, we should take a look at this.
It's a pcb that connects from the serial port of the computer (RS232 DB-9) to our board and looks really easy to make. We might even have the components already in the university.
@goros1993 for now I think we don´t need the device above because we have the ATmega328 programmed with the bootloader.
Now what we need is to talk with it through a USB to I2C interface. I put the link to something similar : http://headfuzz.co.uk/USBtoI2C
From the link above we can download a GUI application code but it works with the OSIF or maybe we can do one application using the OSIFdll or OpenServo API.
I think we can perform the USB to I2C interface uploading a sketch to the Arduino and using Wire library.
Yesterday I setup the environmnet on Raspberry Pi for I2C communication following this tutorial: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
Also I follow this tutorial http://blog.oscarliang.net/raspberry-pi-arduino-connected-i2c/ to probe the connection uploading an sketch to arduino and executing a python script in the rapsberry. The connection was succesful.
But when I wanted to do the same with my own burned uController the raspberry pi didn`t recognize my device.
Today I change the slave address in the bootloader twi.h file to
#define TWI_SLAVE_ADDRESS 0x55
because I think the raspberry only recognize until 0x77 and it was set to 0x79. Also I compile the code with a new MakeFile328 and burn it to the uController again.
Now raspberry can connect recognize the uController through I2C.
OpenServo bootloader
Code compiled using Atmel Studio 7 (Version 7.0.634) tool for ATmega328.
Used complete Datasheet for ATmega328
Some changes have been done to support ATmega328(This uController has more memory than the ATmega168):
1 - Lines added to prog.h
2 - In prog.c Define variables that diffier with:
3 - In timer.h The same like ATmega168.
References in the Datasheet about memory: Pages 266, 276 and 277. In this pages the boot size is in words: 16bit. Because of it the addresses are different from the README.txt.