Hey there,
I’ve been programming the ATmega168 on the Orangutan LV-168 in assembly with the USB Programmer that it came with. Problem is, just recently I have been unable to connect to the connect to the target device. In the “Select AVR Programmer” Prompt, I select AVRISP and Auto (or COM3 in my case) and the window returns with “Connect Failed” at the top. What gives? I did a fresh install of Windows 7 Professional x86 and I installed all of the Windows Vista drivers from this site’s page for the USB Programmer that I have (it’s the one without the SLO function, older one). I set the port settings to 115200-8-N-1 and I can verify that the latest program I flashed on the ATmega168 is working correctly because I can communicate with it via PuTTY with the USB Programmers’ Serial Communications mode. (The program receives characters via USART0 and commands a tank with two DC motors using the motor controllers connected to PORTD and PORTB). I also noticed that the red LED on the LV-168 located by the reset button is now red, but I think that’s because I have PD1(USART0 Tx) connected to Rx on the USB Programmer.The following is my code for the program that should be on there now:
.INCLUDE "m168def.inc"
.DEF tmp = R16
.DEF counter = R17
.DEF tosetstack = R18
.DEF char = R19
.EQU M1A = PD5
.EQU M2A = PD3
.EQU M1B = PD6
.EQU M2B = PB3
.ORG 0x00
RJMP reset
.ORG URXCaddr ;This defines what to do if USART0 Rx interrupt is triggered
RJMP rx_char ;So jump to our interrupt subroutine below
.ORG INT_VECTORS_SIZE ;This starts the main instructions outside of the vector addresses
reset:
LDI tosetstack, HIGH(RAMEND);Upper byte of ramend
OUT SPH,tosetstack ;to stack pointer high
LDI tosetstack, LOW(RAMEND) ;Lower byte of ramend
OUT SPL,tosetstack ;to stack pointer low
SEI ;Enable Interrupts
SBI DDRB, M2B ;Set Motor 2 B to output
LDI tmp, 0x68
OUT DDRD, tmp ;Set Motor 1 A & B, and Motor 2 A to output
LDI tmp, 129 ;We want baud 9600
STS UBRR0L, tmp ;Set low byte for baud to 0x81=129 (depends on cpu clock)
LDI tmp, (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0)
STS UCSR0B, tmp ;This sets receive enable, and receive interrupt enable
LDI tmp, (3<<UCSZ00)
STS UCSR0C, tmp ;Set character size to 8bit, default stop =1, didn't set any parity
LDI tmp, (1<<SE)
OUT SMCR, tmp ;Enable SLEEP commands. Because pins 1-3 are 0-0-0, IDLE sleep is active
LDI tmp, 0x79 ;This selects all pins in PRR except USART0 and SPI
STS PRR, tmp ;Power Reduction Register set
main:
SLEEP ;The processor goes idle while it waits for an interrupt by USART0 Rx Complete
RJMP main
rx_char:
LDS char, UDR0 ;Read the character from the buffer into "char" = R19
STS UDR0, char ;Echo the character back to the controlling terminal
CPI char, 'w' ;Compare character with 'w'
BREQ forward ;If equal, jump to forward
CPI char, 's'
BREQ reverse
CPI char, 'a'
BREQ left
CPI char, 'd'
BREQ right
RJMP brake ;Any other character received, brake
forward:
SBI PORTB, M2B ;Drive Motor 2 B high
SBI PORTD, M1B ;Drive Motor 1 B high
CBI PORTD, M2A ;Drive Motor 2 A low
CBI PORTD, M1A ;Drive Motor 1 A low
RETI ;Return from interrupt
reverse:
SBI PORTD, M2A ;Drive Motor 2 A high
SBI PORTD, M1A ;Drive Motor 1 A high
CBI PORTB, M2B ;Drive Motor 2 B low
CBI PORTD, M1B ;Drive Motor 1 B low
RETI ;Return from interrupt
left:
SBI PORTB, M2B ;Drive Motor 2 B high
SBI PORTD, M1A ;Drive Motor 1 A high
CBI PORTD, M1B ;Drive Motor 1 B low
CBI PORTD, M2A ;Drive Motor 2 A low
RETI ;Return from interrupt
right:
SBI PORTD, M1B ;Drive Motor 1 B high
SBI PORTD, M2A ;Drive Motor 2 A high
CBI PORTB, M2B ;Drive Motor 2 B low
CBI PORTD, M1A ;Drive Motor 1 A low
RETI ;Return from interrupt
brake:
SBI PORTB, M2B ;Drive Motor 2 B high
SBI PORTD, M1B ;Drive Motor 1 B high
SBI PORTD, M2A ;Drive Motor 2 A high
SBI PORTD, M1A ;Drive Motor 1 A high
RETI ;Return from interrupt
Can someone please help me figure out why I can’t connect to the ATmega168 to program it anymore?
EDIT: I also tried updating the firmware to version 1.4 (I have the PGM02B programmer) and changing the software version to say 2.07 (it was 2.0a before). No luck - I keep getting told by AVR Studio that the connect failed.
EDIT: So avrdude works, but AVR Studio doesn’t want to connect. This means that the drivers for the USB Programmer are fine. Does AVR Studio use avrdude? I’d like to be able to program from the GUI without having to open a command prompt and running the command there. Maybe AVR Studio just doesn’t work correctly in Windows 7 (even 32-bit); I installed it and WinAVR both as an administrator.