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.
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.
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.
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.
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: