Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Atmel AVR Studio C programming

Status
Not open for further replies.

shomikc

Member level 4
Member level 4
Joined
Apr 19, 2013
Messages
71
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,953
I started teaching Atmel AVR microcontroller this semester.

I need to reverse an array, the first element of array being swapped with last and second element being swapped with second last and so on.

I am getting a recipe for target *.elf failed error.

Please help.
Code:
#include <avr/io.h>

//void swap (int *px, int *py);

void swap (char *px, char *py)
{
char temp;
temp = *px;
*px = *py;
*py = temp;
}

void reversal (char a[ ], char n)
{
char i, j, k;
 
j = n%2;
// n is the number of elements in the array
if (j == 1)
k = n + 1;
for (i = 0; i < (k)/2 ; i++)
{
swap (&a[i], &a[n - i - 1]);
}
/*for (i = 0; i < n ; i++)
{
printf("%d \n",a[i] );
}*/
}

int main(void)
{
/* Replace with your application code */
char n = 5;
char a[5] = {1, 2, 3, 4, 5};
  
//reversal(a, n);
}
 

What AVR are you using ? The "recipe" error might refer to the
compiler not having the recipe for compiling for the chip you are using.
It may make a difference whether the source file is *.c or *.cpp.
 
Last edited:

    shomikc

    Points: 2
    Helpful Answer Positive Rating
k isn't initialized for even n values. For odd n values, the code superfluously swaps the center element with itself.
 

What AVR are you using ? The "recipe" error might refer to the
compiler not having the recipe for compiling for the chip you are using.
It may make a difference whether the source file is *.c or *.cpp.
Hi. I am using ATxmega128A1 to initialize the project and then I am using the Simulator tool as the debugger.
--- Updated ---

k isn't initialized for even n values. For odd n values, the code superfluously swaps the center element with itself.
Yes, you are right but the code works in other C ide with int instead of char. so that isnt the problem.
 

I compiled your code as a .c file in AVR Studio with the project using ATxmega128A1 with GCC, and it completed successfully, with 4 warnings, no errors.
 

    shomikc

    Points: 2
    Helpful Answer Positive Rating
I compiled your code as a .c file in AVR Studio with the project using ATxmega128A1 with GCC, and it completed successfully, with 4 warnings, no errors.
Thankyou. But I am still not able to fix my error. my assembly files work okay. which version of avr studio are you using?
--- Updated ---

Thankyou. But I am still not able to fix my error. my assembly files work okay. which version of avr studio are you using?
Also can please send me the warnings.
--- Updated ---

Thankyou. But I am still not able to fix my error. my assembly files work okay. which version of avr studio are you using?
--- Updated ---


Also can please send me the warnings.
and do you have a header file of the controller in the dependencies.
--- Updated ---

Thankyou. But I am still not able to fix my error. my assembly files work okay. which version of avr studio are you using?
--- Updated ---


Also can please send me the warnings.
--- Updated ---


and do you have a header file of the controller in the dependencies.
I get the same error even with just avr/io.h and just main() function. Now I get recipe for target main.o failed.
 
Last edited:

I used Atmel AVR studio 7 , (and an old version 6.2). Check that a .c source file is not being built with G++ or a .cpp file being built by GCC

The warning messages are:
Warning 1 array subscript has type 'char'
Warning 2 unused variable 'a'
Warning 3 unused variable 'n'
Warning 4 'k' may be used uninitialized in this function
 
Last edited:

    shomikc

    Points: 2
    Helpful Answer Positive Rating
Hi,
Also can please send me the warnings.
This is what I expected from you...
Because I expected to make your code to work, not FenTrac's code/compiler ...

On the other hand maybe you've learned how important it is to give the errors/warnings for others to get a clue what's going on.

Klaus
 

    shomikc

    Points: 2
    Helpful Answer Positive Rating
Hi. I would like to know if there is any other software to compile C programs for AVR microcontrollers other than AVR studio. Does MPLAB ide provide compilation of C programs forAVR microcontroller
 

Hi. I would like to know if there is any other software to compile C programs for AVR microcontrollers other than AVR studio. Does MPLAB ide provide compilation of C programs forAVR microcontroller
XC8 with MPLab X will compile for AVR
 

    shomikc

    Points: 2
    Helpful Answer Positive Rating
Hi. I kind of figured it out. First we turn off windows defender and finally from Debug option we select Options and once there we select the appropriate Toolchain on the right hand of the pop up window. (It may be necessary to disable the antivirus also.)

For the life of me I cannot understand the connection between windows defender and Microchip or Atmel Studio. The Assembler in Simulator mode works with Windows Defender on.

However I am still unable to print the result in The Output, for example, the maximum array.

If you can help with this.
--- Updated ---

Hi. I kind of figured it out. First we turn off windows defender and finally from Debug option we select Options and once there we select the appropriate Toolchain on the right hand of the pop up window. (It may be necessary to disable the antivirus also.)

For the life of me I cannot understand the connection between windows defender and Microchip or Atmel Studio. The Assembler in Simulator mode works with Windows Defender on.

However I am still unable to print the result in The Output, for example, the maximum array.

If you can help with this.

Sorry, I meant maximum of an array. If anyone can give some guidance on this. I appreciate all the help given.
 
Last edited:

Using printf() with an AVR is complicated. Do a google search for more information on how to do it. Usually, output uses the USART on the AVR through a Serial interface to a terminal, such as a TTL to USB converter. Or, to a display such as a 16x2 LCD attached to the AVR.
 

    shomikc

    Points: 2
    Helpful Answer Positive Rating
Using printf() with an AVR is complicated. Do a google search for more information on how to do it. Usually, output uses the USART on the AVR through a Serial interface to a terminal, such as a TTL to USB converter. Or, to a display such as a 16x2 LCD attached to the AVR.
yes. you are right and it is very complicated. I have tried with USART and not succeeded. thanks. I will keep trying.
 

The microcontroller's datasheet has the information on configuring the USART registers and sample code for C and assembler. Once configured, data can be put in the transmit register one byte at a time, to send it to the terminal. Below are examples for an ATmega328pb USART0 in C.

Code:
C:
  UCSR0A |= (1 << U2X0);    // U2X0 = 1 = set double speed mode
  UCSR0B = (1 << RXEN0) | (1 << TXEN0);  // enable transmit, receive
  UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); // Use 8-bit character sizes
  UBRR0 = 16; // load 115200 baud value  into the UBRR0 register
//---------------------------------------------------------------------------------------
to send a byte:
   UDR0 = a[i];

   a[i] may need to have 0x30 added to it to print as the ascii character for a number on the terminal
The code for the AVR you are using will probably be similar.
 
Last edited:

    shomikc

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top