Home >Class Mar 14 Assignment

Class Mar 14 Assignment

Embedded programming

capacitive communication: make a board to do that and write code to accomplish same (as it turnes out this is the assignment for the 11th week)

Goal to try different programming languages. (list found here)

Listed below are working codes in the different languages: the C-code and the assembler code actually have actually been tried on the tiny44 (my Hello-Board).

// C code
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
   DDRB |= (1<<PB2);
   PORTB |= (1<<PB2);
   
   DDRA &= ~(1<<PA7);
   PORTA |= (1<<PA7);
   
   while (1) {
      if ((PINA & (1<<PA7))) {
         PORTB &= ~(1<<PB2);
      } else {
         PORTB |= (1<<PB2);
      }
   }
}

Calibrating the internal oscillator

We're having quite some issues with tiny45's failing to communicate with the computer.

The problem seems to be insufficiently calibrated oscillators. After some investigation (reading Atmel's appnote AVR053) i found the following:

"Be aware that the new calibration value should be loaded into the OSCCAL register at runtime by the firmware."

This value will be erased when doing a chip-erase; so it is important to retrieve this value before re-programming the chip.

I don't know if this can be done using avrdude.

Also: "The Oscillator calibration byte is written to the device during manufacturing, and can not be erased or altered by the user" as per the avr ISP mkII documentation.

The pre-programmed OSCCAL value is already being loaded by the chip at boot-time, so we would need to setablish a workflow that allows us to do this.

avrdude seems to do a little more automation on this with the '-O' option:

Perform a RC oscillator run-time calibration according to Atmel application note AVR053. This is only supported on the STK500v2, AVRISP mkII, and JTAG ICE mkII hardware. Note that the result will be stored in the EEPROM cell at address 0.

 

^Top