Wednesday, May 18, 2016
Tuesday, May 17, 2016
The i2c bus
Most popular of the serial buses. Uses one wire for clock and one wire for bidirectional data. Based on Phillips' iic network. Lots of chips use the i2c protocol.
Good short introduction here. Not Arduino based.
Using i2c to connect arduino to eeprom chip that holds 256k bits, here.
Interesting use of i2c OLED display.
SPI or i2c. Which one is ""better"?
Good short introduction here. Not Arduino based.
Using i2c to connect arduino to eeprom chip that holds 256k bits, here.
Interesting use of i2c OLED display.
SPI or i2c. Which one is ""better"?
Monday, May 16, 2016
The SPI bus
Using AVR Studio programs in an Arduino (Not required for 2016, but asm blink program is relevant)
Programs needed are just AVR Studio and avrdude. I used AVR Studio version 4.14 and the avrdude that came with the Arduino suite.
Step 1. Write your program in assembler in AVR Studio, build then save the hex file.
Step 2. Go into the command prompt and invoke avrdude with the right switches.
I started with the usual Arduino C blink program, just to make sure I got the COM port right and to see the hardware was all working. Then did steps above.
Below are some relevant screen shots.
Blink for AVR Studio 4 assembler
.include "m328pdef.inc"
;Based on http://www.robertoinzerillo.com/wordpress/?p=5
;-----------------------------------------;
; FIRST WE'LL DEFINE SOME REGISTER TO USE ;
;-----------------------------------------;
.DEF A = R16 ;GENERAL PURPOSE ACCUMULATOR
.DEF I = R21 ;INDEXES FOR LOOP CONTROL
.ORG $0000
;-----------------------------------------;
; FIRST WE SETUP A STACK AREA THEN SET ;
; DIRECTION BIT ON PORT-B FOR OUTPUT/SPKR ;
;-----------------------------------------;
START:
LDI A,LOW(RAMEND) ;SETUP STACK POINTER
OUT SPL,A ;SO CALLS TO SUBROUTINES
LDI A,HIGH(RAMEND) ;SETUP STACK POINTER
OUT SPH,A ;SO CALLS TO SUBROUTINES
LDI A,0b1111_1111 ;SET ALL PORTB FOR OUTPUT
OUT DDRB,A ;WRITE 1s TO DIRECTN REGS
;--------------;
; MAIN ROUTINE ;
;--------------;
LEDONOFF:
SER A
OUT PORTB,A
RCALL DELAYLONG
CLR A
OUT PORTB,A
RCALL DELAYLONG
RJMP LEDONOFF
DELAYLONG:
; =============================
; Delaying approximately 1 sec at 8Mhz.
; This code has been created with “AVR Delay Loop Generator V1.2?.
ldi R17, $48
WGLOOP0: ldi R18, $BC
WGLOOP1: ldi R19, $C4
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
; =============================
RET
Step 1. Write your program in assembler in AVR Studio, build then save the hex file.
Step 2. Go into the command prompt and invoke avrdude with the right switches.
I started with the usual Arduino C blink program, just to make sure I got the COM port right and to see the hardware was all working. Then did steps above.
Below are some relevant screen shots.
Blink for AVR Studio 4 assembler
.include "m328pdef.inc"
;Based on http://www.robertoinzerillo.com/wordpress/?p=5
;-----------------------------------------;
; FIRST WE'LL DEFINE SOME REGISTER TO USE ;
;-----------------------------------------;
.DEF A = R16 ;GENERAL PURPOSE ACCUMULATOR
.DEF I = R21 ;INDEXES FOR LOOP CONTROL
.ORG $0000
;-----------------------------------------;
; FIRST WE SETUP A STACK AREA THEN SET ;
; DIRECTION BIT ON PORT-B FOR OUTPUT/SPKR ;
;-----------------------------------------;
START:
LDI A,LOW(RAMEND) ;SETUP STACK POINTER
OUT SPL,A ;SO CALLS TO SUBROUTINES
LDI A,HIGH(RAMEND) ;SETUP STACK POINTER
OUT SPH,A ;SO CALLS TO SUBROUTINES
LDI A,0b1111_1111 ;SET ALL PORTB FOR OUTPUT
OUT DDRB,A ;WRITE 1s TO DIRECTN REGS
;--------------;
; MAIN ROUTINE ;
;--------------;
LEDONOFF:
SER A
OUT PORTB,A
RCALL DELAYLONG
CLR A
OUT PORTB,A
RCALL DELAYLONG
RJMP LEDONOFF
DELAYLONG:
; =============================
; Delaying approximately 1 sec at 8Mhz.
; This code has been created with “AVR Delay Loop Generator V1.2?.
ldi R17, $48
WGLOOP0: ldi R18, $BC
WGLOOP1: ldi R19, $C4
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
; =============================
RET
Tuesday, May 10, 2016
Setting up stack for subroutines
The code for the above program is:
.include "m328pdef.inc"
start: ;set up the stack
ldi r16, low(RAMEND)
out SPL, r16
ldi r16, high(RAMEND)
out SPH, r16
nop
call below
nop
finish: rjmp finish
below:
ldi r17,$99
ret
The relevant part of the def.inc file the shows what RAMEND is for this processor is:
; ***** CPU REGISTER DEFINITIONS *****************************************
.def XH = r27
.def XL = r26
.def YH = r29
.def YL = r28
.def ZH = r31
.def ZL = r30
; ***** DATA MEMORY DECLARATIONS *****************************************
.equ FLASHEND = 0x3fff ; Note: Word address
.equ IOEND = 0x00ff
.equ SRAM_START = 0x0100
.equ SRAM_SIZE = 2048
.equ RAMEND = 0x08ff
.equ XRAMEND = 0x0000
.equ E2END = 0x03ff
.equ EEPROMEND = 0x03ff
.equ EEADRBITS = 10
#pragma AVRPART MEMORY PROG_FLASH 32768
#pragma AVRPART MEMORY EEPROM 1024
#pragma AVRPART MEMORY INT_SRAM SIZE 2048
#pragma AVRPART MEMORY INT_SRAM START_ADDR 0x100
; ***** BOOTLOADER DECLARATIONS ******************************************
.equ NRWW_START_ADDR = 0x3800
.equ NRWW_STOP_ADDR = 0x3fff
.equ RWW_START_ADDR = 0x0
.equ RWW_STOP_ADDR = 0x37ff
.equ PAGESIZE = 64
.equ FIRSTBOOTSTART = 0x3f00
.include "m328pdef.inc"
start: ;set up the stack
ldi r16, low(RAMEND)
out SPL, r16
ldi r16, high(RAMEND)
out SPH, r16
nop
call below
nop
finish: rjmp finish
below:
ldi r17,$99
ret
The relevant part of the def.inc file the shows what RAMEND is for this processor is:
; ***** CPU REGISTER DEFINITIONS *****************************************
.def XH = r27
.def XL = r26
.def YH = r29
.def YL = r28
.def ZH = r31
.def ZL = r30
; ***** DATA MEMORY DECLARATIONS *****************************************
.equ FLASHEND = 0x3fff ; Note: Word address
.equ IOEND = 0x00ff
.equ SRAM_START = 0x0100
.equ SRAM_SIZE = 2048
.equ RAMEND = 0x08ff
.equ XRAMEND = 0x0000
.equ E2END = 0x03ff
.equ EEPROMEND = 0x03ff
.equ EEADRBITS = 10
#pragma AVRPART MEMORY PROG_FLASH 32768
#pragma AVRPART MEMORY EEPROM 1024
#pragma AVRPART MEMORY INT_SRAM SIZE 2048
#pragma AVRPART MEMORY INT_SRAM START_ADDR 0x100
; ***** BOOTLOADER DECLARATIONS ******************************************
.equ NRWW_START_ADDR = 0x3800
.equ NRWW_STOP_ADDR = 0x3fff
.equ RWW_START_ADDR = 0x0
.equ RWW_STOP_ADDR = 0x37ff
.equ PAGESIZE = 64
.equ FIRSTBOOTSTART = 0x3f00
Tuesday, May 3, 2016
Assembler delays
Using delays in AVR studio
Write a variation on the above program to produce any delay required fro your project.
Write a variation on the above program to produce any delay required fro your project.
Monday, May 2, 2016
Subscribe to:
Posts (Atom)









