FAQ Database Discussion Community


Interrupt programming for AVR ATmega48

c,microcontroller,interrupt,avr,atmega
I have a small task to program the following using C, for an ATmega48 controller: In the beginning, all (6) LEDs are turned on. When button SW1 is pressed, LEDs are only allowed to be turned off with the respective buttons. When button SW2 is pressed, LEDs are only allowed...

AVR Switch Input

assembly,avr,atmel
how do we get this program to read input from switch 0 instead of switch 7. At the moment the I'm not sure where the code is checking for the input, and I don't know how to change it. I think its to do with brmi right, but I might...

Explain This Instruction Set And Z-Register

assembly,avr
I'm not understanding the following code very well. Specifically, what does the two lines with the question marks do? What does seg_table<<1 do? In general, what is the purpose of the z-register? nc1_m: lpm r21, z ldi zh, high(seg_table<<1) <--? ldi zl, low(seg_table<<1) <--? add zl, r20 brcc nc2_m inc...

saving an array in EEPROM

c,avr
I've a vectorx[8] and I want to save its value in the EEPROM of an XMEGA for that here is what I've done :: ............................ int16_t vec1[8]; int16_t vec2[8]; int16_t vec3[8]; int i = 0, j =1; for ( i =0 ; i<8; i++){ // ini vec1[i] = 23500; vec2[i]...

#define a tuple in C

c,c-preprocessor,avr
I want to be able to define a tuple which represents the arguments needed by other macros. I think the best way to show what I want is to show an example: #include <avr/io.h> #define LED_PORT PORTB #define LED_DDR DDRB #define LED_PIN PB7 #define LED LED_PORT, LED_DDR, LED_PIN #define OUTPUT(port,...

ATtiny84 pwm led flicker

avr,pwm,attiny
I'm fairly new to avr programming and I'm trying to simply fade 3 leds independently connected to ATtiny84 pwm pins. Right now I have code that should chnage brightness of two different leds. Here is my code: #define F_CPU 1000000UL #include <avr/io.h> #include <util/delay.h> int main(void) { DDRB |= (1...

Avr-g++ compilation failed with Make Error 1

eclipse,arduino,make,avr,avr-gcc
I'm trying to compile arduino code in Eclipse. Below is build log. make all Building file: ../test.cpp Starting C++ compile "/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=163 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I"/opt/arduino-1.6.3/hardware/arduino/avr/cores/arduino" -I"/opt/arduino-1.6.3/hardware/arduino/avr/variants/standard" -I/usr/lib/avr/include -MMD -MP -MF"test.cpp.d" -MT"test.cpp.d" -D__IN_ECLIPSE__=1 -x c++ "../test.cpp" -o...

Software interrupts on AVR

posix,interrupt,system-calls,avr,syscall
I understand that x86 machine code can make POSIX system calls using software interrupts (by entering a 32-bit value corresponding to a kernel function into the EAX register of the processor and then executing INT 0x80). I'm looking into designing a small Unix-like operating system for the AVR architecture for...

Arduino Programming Without Arduino Libraries - Atmel Studio

arduino,avr,atmega,avrdude,atmelstudio
I would think this question has been asked thousands of times, I simply cannot find many resources on the subject. I would like to program my Arduino Uno (ATmega328P) using Atmel Studio and the C language, minus the Arduino Libraries. What I mean by this is that I would like...

glitches when using time overflow interrupt

c,timer,interrupt,avr,attiny
I have some trouble with, I guess, the overflow interrupt (used to increase resolution on 8-bit timer from 16µs/step to 1µs/step) in my CODE. It seems like the overflow interrupt triggers while the program is in the if-statements in my main loop and thereby screws thigns up! if(pInt == 1)...

Two ISR with the same timer AVR

timer,interrupt,avr
I'd like to know if it's possible to use 2 different ISR (e.g. ICP input capture and timer overflow) in AVR microcontrollers

SPI with Atmega32 and At42QT2100

c,avr,spi,atmel
I have a problem to communicate from an Atmega3216PU to a at42qt2100. The datasheets are: Atmega32PU16 and AT42QT2100 This is my code: #include <avr/io.h> #include <util/delay.h> #include <stdio.h> #define F_CPU 16000000 #define UART_BAUD_RATE 9600 #define UART_BAUD_REGISTERS (((F_CPU / (UART_BAUD_RATE * 16UL))) - 1) int printCHAR(char character, FILE *stream) { while...

Codevision AVR access external eeprom 24c02B using TWI

c,embedded,microcontroller,avr,eeprom
I'm a beginner in C. I'm trying to write and read to external eeprom (AT24c02B) then show the data bytes that store in eeprom to LED in PORTB and or to LCD. So I know the data successfully stored in eeprom. LED in PORTB is active low. Here is the...

Creation and addressing arrays in AVR Assembly (Using the ATMega8535)

arrays,assembly,avr,atmel
I am having trouble with the creation and addressing of an array created purely in assembly using the instruction set for the Atmel ATMega8535. What I understand so far is as follows: The array contains contiguous data that is equal in length. The creation of the array involves defining the...

255 char. instead of 1023, Unable to set reference voltage

avr,analog-digital-converter,atmega16
I am using ATmega16 in my project. I want to get the value=1023 when I give 5V as input, and 0 when input = 0. The readADC function reads the particular channel of micro-controller ADC. The frequency of my clock is 4MHz. But on reading the input, I'm getting 255...

DistinguishingFalling and rising Edges in XMEGA

c,avr
I've got 3 buttons that should generate interrupts each time they've been pressed or released, the issue that I have is, that I need to distuiguish what really happens ( realsing or pressing the button ) , here is my code : .................. ISR(PORTA_INT0_vect){ if(!(PORTA.IN & PIN1_bm)){ // Green LED...

reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers

c++,avr,avr-studio6
I want to use Adafruit_CC3000 arduino library in AVR Studio. I have followed this Instruction to use Adafruit arduino lib with AVR studio so i can use other AVR function too. But I am getting the same error 50 times while i compile the code. Error 5 reinterpret_cast from type...

External interrrupt always run

assembly,microcontroller,avr
In my reset interrupt I set up external interrupt (to react on button click). But interrupt handler code called without button clicking. Why? (Atmega8 microcontroller) EXT_INT0: ldi temp, 0b0000001 out PORTB, temp ldi temp, 0b0000000 out PORTC, temp reti RESET: cli ldi temp,HIGH(RAMEND) ; set stack register out SPH,temp ldi...

Writing to flash ROM for an embedded OS on atmega328p (h8write equivalent for avr)

arduino,embedded,avr,rtos,atmega
I'm currently reading a Japanese book on embedded OS/RTOS es except that I am not using the recommended hardware as I already had a seeeduino microcontroller.(atmega328p) The book is about KOZOS "12 steps to making your own embedded OS" by Sakai Hiroaki(It's hiro-something) I'm stuck at the part where I...

Advice on RTOS for AVR?

avr,avr-gcc,rtos
I need a very tiny RTOS for AVR similar to mRTOS which just has two files (mrtos.h and mrtos.c). Can anyone please provide any advice?...

avr-gcc atmega164pa error port undeclared

avr,avr-gcc,atmega,atmel
When compiling the following code: #define F_CPU 1000000UL #include <avr/io.h> #include <util/delay.h> int main(void) { DDRC = 255; while(1){ PORTC=255; _delay_ms(200); PORTC=0; _delay_ms(200); } return 0; } for ATMega16 is fine: avr-gcc -w -Os -DF_CPU=1000000UL -mmcu=atmega16 -c -o main.o main.c However, for ATMega164PA, I get these errors: avr-gcc -w -Os...

How to assign a specific [x] value to port pin?

c,avr
How can I assign dynamic value to a pin a specific pin on my AVR chip. For instance I have: void life_reset(void){ PORTC |= (1<<PC0); PORTC |= (1<<PC1); PORTC |= (1<<PC2); life_number = 2; } void lost_life(void){ life_number--; PORTC &= ~(1<<PC2); } Which decrements my life_number variable and bitwise AND's...

How handle directions with interrupt in Proteus

avr,atmega,atmega16
I want to implement Snake game with Atmega16 I following this tutorial. My problem is I couldnt handle the KeyPad ! I found another tutorial (here) about one Button with interrupt But in Snake we need 4 button for our directions And I dont know how to handle this in...

How to shift 111 starting with 00000001 Assembler

assembly,byte,bit,avr,shift
I need to shift value of register in a loop. I need to start with a 00000001 -> 00000011 -> 00000111 -> 00001110 -> 00011100 -> 00111000 -> 01110000 -> 11100000 -> 01110000 -> 00111000-> 00011100-> 00001110-> 00000111 -> 00000011 -> 00000001 . I have no idea how to do...

AVR C random behaviour when setting flags with enum

c,enums,avr
I have a Problem with enums and flags which I'm using for a programme state from a AVR C Application on a atmega1280 µC, below is the code how I handle the Flags: typedef enum { ALARM_FLAG, ARMED_FLAG, RC_AUTH_FLAG, ADC_DATA_READY_FLAG, PLAY_MUSIC_FLAG, PLAY_ALARM_FLAG, MUSIC_DREQUEST_FLAG, SENSOR_CHANGE_FLAG, RFID_DECODED_FLAG, RFID_AUTH_FLAG, RFID_ENABLE_FLAG, RFID_DISABLE_FLAG, REMOTE_RX_COMPLETE, REMOTE_TX_COMPLETE,...

Shift value to some point in binary number

assembly,microcontroller,avr
I wonder if it is possible to do the following. For instance, I have a number 00001110. I am shifting it left. -> 00011100.... But the question is if it possible to start setting value in carry flag not from the seventh bit but from the sixth. There is a...

UART only working correctly one way (ATmega328p)

avr,uart
I got an Arduino Uno, which is driven by an ATmega328P. And I wanted to move away from its libraries and do everything on a lower level for learning purposes. However I cannot get the uart working correctly, it works now only when sending to the device. Receiving returns weird...

knowing the value ldi command is placing in X, Y, Z-Register

pointers,assembly,avr
How can you know what value the different registers get when I am running the program? like we see in picture 1, after line 8 the R30 register(Z-Pointer) is changed to 0x94 and if I run one more line R29 become 0x01. but R28 and R31 have no value change....

Implicit declaration of function and conflicting type - AVR

c++,c,compiler-errors,avr,atmega16
This is my first program for AVR. While building, the code is showing error: conflicting types for 'Encode' implicit declaration of 'Encode' I have written the following code: #include <avr/io.h> #include <util/delay.h> #include <stdlib.h> #define SegDataPort PORTC #define SegDataPin PINC #define SegDataDDR DDRC #define SegCntrlPort PORTD #define SegCntrlPin PIND #define...

Why I am always getting Zero PWM output?

avr,pwm,atmega16
I want to output two different analog values with 10 bit resolution i.e. dac_value ranging from 0-1023. I am using ATmega16 with external crystal 4MHz. I have also tried connecting RC filter at output but nothing changed. I am constantly getting zero output, can someone help ?? #include <avr/io.h> #include...

Digits not displayed properly, Unable to control output at particular pin

c,avr,led,atmega,atmega16
I am trying to display my input at microcontroller ATmega16 to 7 segment displays. I have found the following code on http://www.avr-tutorials.com/projects/atmega16-based-digital-clock but when I implimented it, it is not working. I am getting a fluctuating output i.e I am not able to control the output at particular pins. I...

Issue with uint64_t type

c,bitwise-operators,avr,bit-shift,unsigned-integer
say I have the the following union : typedef union { char array[8]; uint64_t u64; } my_type ; I want to shift one bit 1 through all the 64 bits the reserved, here is what I've tried : ........................... my_type vector ={0}; short index =0; for ( index=0 ; index...

bit comparison in loop on AVRs

c,bit,avr,led,operations
I'm learning about bit logic in C on AVRs and I have a problem. I want to compare an "i" bit (from the right) from int8_t variable and if it is 1, then do the next instruction, but it doesn't work. Here's what I write: if (variable & (1<<i)==(1<<i)) instruction;...

Changing just one byte in SD card sector

c,embedded,avr
I'm implementing FAT16 on SD card with Atmega328. I often need to change just one or two bytes in the sector (512B region). I know how Flash works and that it needs to overwrite entire sector at once, but I was wondering if there maybe was some special command that...