Problem with the UART in Atmel Studio 7 with ATMega 328P on the Arduino Board

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone, again I found some problem when I tried to upload the program that will take my character input and display the ASCII value on the LEDs based on the "Make: AVR Programming" book and I did the modification to make it work on my UNO clone board (ATMega 328p SMD Based) that runs on default at 16 MHz clock speed but I change my MCU to run at 1MHz clock speed, my modification code looks as follows:

 

/*
A simple test of serial-port functionality.
Takes in a character at a time and sends it right back out,
displaying the ASCII value on the LEDs.
*/

 

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/power.h>
#include "pinDefines.h"
#include "uart.h"

int main(void) {
    clock_prescale_set(clock_div_16);  //run your 16MHz hardware at 1MHz
    char serialCharacter;
    // -------- Inits --------- //
    LED_DDR = 0xff; /* set up LEDs for output */
    initUSART();
    printString("Hello World!\r\n"); /* to test */
    // ------ Event loop ------ //
    while (1) {
        serialCharacter = receiveByte();
        transmitByte(serialCharacter);
        LED_PORT = serialCharacter;
        /* display ascii/numeric value of character */
        } /* End event loop */
        return (0);
    }

 

but when I tried to upload the program, there was this error and I believe that my code is not being uploaded properly to the board:

1. there is so-called like a "not in sync" error code as shown in the below picture

 

 

Is it possible for everyone here to check what was my issue here and help me to solve it?  because I have done these following steps:

 

1. include all the required .h file and .c file in my project 

2. setting my baud rate become 9600 in my USART.h file as shown in the following picture

 

2. and the USART.c file that I include has a following code:

 

 

 

 

 

Embedded Lover and would like to pursue my future in embedded system

Last Edited: Fri. Jul 12, 2019 - 03:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The two missing headers don't come with the compiler.
.
I guess they are something from your book?

Last Edited: Wed. Jul 10, 2019 - 12:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hint. The header files are in double quotes. This implies local files. System includes use wedges not quotes.
.
I would guess that there will be sample "pindefines.h" somewhere in your book.
If you are using a different AVR chip you might need to customise these local files.
System files are included but NEVER edited by the user.
.
David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Hint. The header files are in double quotes. This implies local files. System includes use wedges not quotes.
.
I would guess that there will be sample "pindefines.h" somewhere in your book.
If you are using a different AVR chip you might need to customise these local files.
System files are included but NEVER edited by the user.
.
David.

 

clawson wrote:

The two missing headers don't come with the compiler.
.
I guess they are something from your book?

 

I got it from this link :  https://github.com/hexagon5un/AVR-Programming/tree/master/AVR-Programming-Library

but I don't know where should I put the .h file in my atmel studio 7, do you have any idea about it?

Embedded Lover and would like to pursue my future in embedded system

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

By default 

#include "anything.h"

looks for the .h file in the same directory as the .c file where the #include appears - so just put all the files together in one directory and:

#include "pindefines.h"
#include "USART.h""

should just work.

 

Actually this kind of raises the question of where DID you put the .h files if they aren't just in that same directory? If they are in a "near by" directory like "src\include\" or something then you might use either:

#include "include\pindefines.h"
#include "include\USART.h""

or better yet just stick with the plain #includes then pass:

-I .\include

on the compilation which says to the preprocessor "as well as looking in the current directory for "" includes also look in the .\include\ directory that is near by too".

Last Edited: Wed. Jul 10, 2019 - 02:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But a little added clarification. Program header (your own or library) files are best put into the project directory, along with the code files. Don't touch system header files.

 

One thing that trips up some folks is that you DO NOT "Add" header files to the project. You reference them with #include statements. In the AS7 Solution Explorer pane, they are listed under "Dependencies" once you have a successful compile. You SHOULD NOT see them listed with code files.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

By default 

#include "anything.h"

looks for the .h file in the same directory as the .c file where the #include appears - so just put all the files together in one directory and:

#include "pindefines.h"
#include "USART.h""

should just work.

 

Actually this kind of raises the question of where DID you put the .h files if they aren't just in that same directory? If they are in a "near by" directory like "src\include\" or something then you might use either:

#include "include\pindefines.h"
#include "include\USART.h""

or better yet just stick with the plain #includes then pass:

-I .\include

on the compilation which says to the preprocessor "as well as looking in the current directory for "" includes also look in the .\include\ directory that is near by too".

 

ka7ehk wrote:

But a little added clarification. Program header (your own or library) files are best put into the project directory, along with the code files. Don't touch system header files.

 

One thing that trips up some folks is that you DO NOT "Add" header files to the project. You reference them with #include statements. In the AS7 Solution Explorer pane, they are listed under "Dependencies" once you have a successful compile. You SHOULD NOT see them listed with code files.

 

Jim

 

david.prentice wrote:

Hint. The header files are in double quotes. This implies local files. System includes use wedges not quotes.
.
I would guess that there will be sample "pindefines.h" somewhere in your book.
If you are using a different AVR chip you might need to customise these local files.
System files are included but NEVER edited by the user.
.
David.

Yes I got it to be built successfully but now I get a new error when I tried to upload my code to the ATMega 328P on my UNO board, the error code was:

avrdude.exe : Version 6.3, compiled on Jan 17 2017 at 12:00:53
              Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
              Copyright (c) 2007-2014 Joerg Wunsch

              System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

              Using Port                    : COM3
              Using Programmer              : arduino
              Overriding Baud Rate          : 115200
avrdude.exe : stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude.exe : stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

avrdude.exe  done.  Thank you.
 

Embedded Lover and would like to pursue my future in embedded system

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dumb question, are you sure its on COM3 ???

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
stack gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

Dumb question, are you sure its on COM3 ???

 

Jim

 

 

Yes for the Uno board it's on COM3 as my device manager showed

but when I tried to open my terminal apps it showed my hello world

 

Embedded Lover and would like to pursue my future in embedded system