Setting in boards.txt for ATMega328P

Hi.

How would the board settings in the boards.txt-file be for a breadboarded ATMega328P-PU, with external 8MHz crystal?

Currently I'm using a ATMega168A-PU, but I need some more memory.

This is my board-file, but I think the ATMega328 settings are wrong.

# See: http://code.google.com/p/arduino/wiki/Platforms

menu.cpu=Processor

##############################################################

mega.name=Arduino Mega or Mega 2560

mega.vid.0=0x2341
mega.pid.0=0x0010
mega.vid.1=0x2341
mega.pid.1=0x0042
mega.vid.2=0x2A03
mega.pid.2=0x0010
mega.vid.3=0x2A03
mega.pid.3=0x0042

mega.upload.tool=avrdude
mega.upload.maximum_data_size=8192

mega.bootloader.tool=avrdude
mega.bootloader.low_fuses=0xFF
mega.bootloader.unlock_bits=0x3F
mega.bootloader.lock_bits=0x0F

mega.build.f_cpu=16000000L
mega.build.core=arduino
mega.build.variant=mega
# default board  may be overridden by the cpu menu
mega.build.board=AVR_MEGA2560

## Arduino Mega w/ ATmega2560
## -------------------------
mega.menu.cpu.atmega2560=ATmega2560 (Mega 2560)

mega.menu.cpu.atmega2560.upload.protocol=wiring
mega.menu.cpu.atmega2560.upload.maximum_size=253952
mega.menu.cpu.atmega2560.upload.speed=115200

mega.menu.cpu.atmega2560.bootloader.high_fuses=0xD8
mega.menu.cpu.atmega2560.bootloader.extended_fuses=0xFD
mega.menu.cpu.atmega2560.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex

mega.menu.cpu.atmega2560.build.mcu=atmega2560
mega.menu.cpu.atmega2560.build.board=AVR_MEGA2560

## Arduino Mega w/ ATmega1280
## -------------------------
mega.menu.cpu.atmega1280=ATmega1280

mega.menu.cpu.atmega1280.upload.protocol=arduino
mega.menu.cpu.atmega1280.upload.maximum_size=126976
mega.menu.cpu.atmega1280.upload.speed=57600

mega.menu.cpu.atmega1280.bootloader.high_fuses=0xDA
mega.menu.cpu.atmega1280.bootloader.extended_fuses=0xF5
mega.menu.cpu.atmega1280.bootloader.file=atmega/ATmegaBOOT_168_atmega1280.hex

mega.menu.cpu.atmega1280.build.mcu=atmega1280
mega.menu.cpu.atmega1280.build.board=AVR_MEGA

##############################################################
atmega168a.name=ATmega168A-PU on a breadboard (8 Mhz)

atmega168a.upload.tool=avrdude
atmega168a.upload.protocol=arduino

atmega168a.bootloader.tool=avrdude
atmega168a.bootloader.unlock_bits=0x3F
atmega168a.bootloader.lock_bits=0x0F

atmega168a.build.board=AVR_PRO
atmega168a.build.core=arduino:arduino
atmega168a.build.variant=arduino:standard

atmega168a.upload.maximum_size=14336
atmega168a.upload.maximum_data_size=1024
atmega168a.upload.speed=19200

atmega168a.bootloader.low_fuses=0xc6
atmega168a.bootloader.high_fuses=0xdd
atmega168a.bootloader.extended_fuses=0x00
atmega168a.bootloader.file=atmega/ATmegaBOOT_168_pro_8MHz.hex

atmega168a.build.mcu=atmega168a
atmega168a.build.f_cpu=8000000L

##############################################################
atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=19200

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05

atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard


atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.upload.tool=arduino:avrdud

The file is located at /downloads/arduino-1.6.5/hardware/arduino/avr

I'm on a computer running Ubuntu, and my programmer is a AVR MK II ISP.
I use this to program the microcontroller

sudo avrdude -c avrispmkii -p m328p -P usb -e -U flash:w:filename.hex

The problem I am facing is that my program works if I compile and upload it on my Mega 2560 board, but it will not fit on the ATMega168 uC, because of the memory issue.

Therefore I thought of using a 328P on a breadboard.

Anyone?

  • nerdegutta

You can just use the built-in "Arduino Pro or Pro Mini" board selection with 3.3V 8MHz processor selection.

Hm... OK. I'll try.

Thanks.

  • nerdegutta

Thanks, that seemed to work.

Now I need to figure out why my program is not working the way I want.

I have a LC Soft SD card reader. Connected to PIN 50(MISO), 51(MOSI) and 52(SCK) on the Mega2560. Everything is working, and the SD card is detected, and I can write to it.

Now I want to run that program on ATMega328P. So I stared with a flashing LED, to see that power and crystal was connected right. Then I added a LC Soft SD card reader. I'm using the AVR MKII ISP programmer to program this, and I'm already using the MISO, MOSI and SCK pins. Therefor I've added 4K7 resistors between the SD card readers connection to the IC, so the programmer pins are connected directly. I can program the IC this way. When I burn my other program, nothing is written on the SD card.

Strange...

Anyways, thanks for the reply.

  • nerdegutta

nerdegutta:
Now I need to figure out why my program is not working the way I want.

I have a LC Soft SD card reader. Connected to PIN 50(MISO), 51(MOSI) and 52(SCK) on the Mega2560. Everything is working, and the SD card is detected, and I can write to it.

You'll have to change those pin assignments (MOSI, MISO, SCK) to the Uno's.

I am, or at least I think I am. I'm using this:

I'm able to program the IC with the AVR MKII ISP connected to pin 17, 18 and 19. But I cannot write to the SD card from this IC.

If I program the Arduino Mega from within the Arduino IDE, all works fine.

What's up with that?

  • nerdegutta.

nerdegutta:
I'm able to program the IC with the AVR MKII ISP connected to pin 17, 18 and 19. But I cannot write to the SD card from this IC.

If I program the Arduino Mega from within the Arduino IDE, all works fine.

What's up with that?

  • nerdegutta.

The UNO, and the Mega2560 have different pins assigned to MISO, MOSI, SCK, SS. If you hardcode 50 as the pin number for MISO, it will only work on the Mega2560.

Example:

void setup(){
   pinMode(50,OUTPUT); // set MISO for output will only work on mega
   pinMode(12,OUTPUT); // set MISO for output will only work for UNO

   pinMode(MISO,OUTPUT); // will work for both UNO and MEGA2560, MISO is a define that is set when
                                      // you select which board you are using (under Tools)
}

If you are using the same code on different models of Arduino's you have to either use the predefined constants for change the code for each model.

if you select Arduino Pro, as dmjlambert recommended, you will get the correct clock fuse settings and the core timing routines will be adjusted for a 8mhz clock instead of the 16mhz clock. This will affect everything that is timing dependent. Like Serial.begin(),tone(),delay(),millis() ...

dmjlambert:
You can just use the built-in "Arduino Pro or Pro Mini" board selection with 3.3V 8MHz processor selection.

chuck.

OK. Thanks for your reply.

I have not hardcoded anything.
I've connected the SD card to the MISO, MOSI and SCK according to the pinmap in my previous post, with 4K7 resistors. I've also connected the AVR MKII ISP to these PINS. I've tried with and without the programmer connected.
I've set the board as Arduino Pro, compiled it and uploaded it to the ATMega328P on a breadboard, with this command:

sudo avrdude -c avrispmkii -p m328p -P usb -e -U flash:w:DHT11-SD-logger-v1.cpp.hex

This is my code:

/* Mega 2560
 * PIN 50 = MISO
 * PIN 51 = MOSI
 * PIN 52 = SCK
 * 
 * ATMega328P
 * PIN 17 = MOSI
 * PIN 18 = MISO
 * PIN 19 = SCK
 */

#include <DHT.h>
#include <SPI.h>
#include <SD.h>

#define dhtPin 2 // ATMega328 PIN 4
#define dhtType DHT11

const int chipSelect = 10; // ATMeage 328 PIN 16

int h; // Variable for humidity
int t; // variable for temperature


String dataString = "";

DHT dht(dhtPin, dhtType);

void setup() {
  Serial.begin(9600);
  dht.begin();
  if (!SD.begin(chipSelect))
  {
    Serial.println("Card failed, or not present");
    return;
  }
  Serial.println("Card initialized.");
}

void loop() {
  h = dht.readHumidity();
  t = dht.readTemperature();
  Serial.print("Huimdity: ");
  Serial.print(h);
  Serial.print("%\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println("*C");

  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if (dataFile)
  {
    dataFile.print(h);
    dataFile.print(";");
    dataFile.println(t);
    dataFile.close();
    Serial.print(h);
    Serial.print(";");
    Serial.println(t);   
  }
  else
  {
    Serial.print("Error opening file");
  }
  delay(2000);
}

This works on the Mega2560 board, but not on my breadboarded ATMega328P. :frowning:

  • nerdegutta

OK, now perhaps you should read the instructions for posting.

Please go back to each of your previous entries and modify your "quote" tags to "code".

Paul__B:
OK, now perhaps you should read the instructions for posting.

Please go back to each of your previous entries and modify your "quote" tags to "code".

Thanks! Yes, that would be a good idea. :slight_smile:

EDIT:
Actually, I knew about the code-tag, and I do not know why a bell in my head did not start to ring, when I posted the source code - Sorry!