Hello,
I've been trying to make an EEPROM programmer using an Atmega32 for a while now, and I think I'm one or two stupid errors away from completion...
For my burning code, I have a loop to detect if there is any serial data waiting. From what I can tell, it has 2 options; send the "NEXT" command, or process a
byte from the buffer. However, I sometimes get 2048 bytes to send, but more often than not, I can't get past 64. The RX/TX lights on the USB/Serial converter
are not on, so something is frozen. Resetting the chip allows me to repeat this process, but without a reset, it will not give me anything.
My PC side program is written in python, and if anyone thinks that is the problem, I'll post it as well. Any help is much appreciated. Thank you
#include <stdint.h>
//**************************************************************************************
//**************************************************************************************
//**************************************************************************************
//**************************************************************************************
//**USING PORT B TO WRITE DATA FASTER. THIS IS DIFFERENT FROM THE OTHER VERSION*********
//**************************************************************************************
//**************************************************************************************
//**************************************************************************************
//**************************************************************************************
// On my board, I've connected digital pins 0-15
// to the A0-A15 lines, and digital pins 24-31 (Port "B") to the Q0-Q7 lines.
#define MAX_ADDR 65536L //Max address for the chip
#define AD0 0 //Address pins
#define OE 18 //Output enable pin
#define CE 19 //Chip Enable pin
#define A9S 20 //A9 12V Super Voltage Relay
#define OES 21 //OE 12V Super Voltage Relay
#define PWR 22 //All Good LED Pin
#define ERR 23 //Error LED pin
#define serbaud 115200 //baudrate
int i; //Generic variable
void setup() {
// Setup Control Pins
pinMode(OE, OUTPUT);
pinMode(CE, OUTPUT);
pinMode(A9S, OUTPUT);
pinMode(OES, OUTPUT);
// Disable Chip, and disable read and write.
digitalWrite(CE, LOW);
digitalWrite(OE, HIGH);
//Disable program and erase
digitalWrite(A9S, LOW);
digitalWrite(OES, LOW);
//Serial.begin(115200);
Serial.begin(serbaud);
}
void writeAddr(uint32_t addr) {
uint32_t mask = 0x01;
for (int i = AD0; i < AD0+16; i++) {
if ((mask & addr) != 0) {
digitalWrite(i,HIGH);
}
else {
digitalWrite(i,LOW);
}
mask = mask << 1;
}
digitalWrite(OE,LOW);
}
/*
//**********************************************************************
//**********************************************************************
//I DONT THINK ILL NEED THIS IF I CAN USE PORT MANIPULATION CORRECTLY!!!
//**********************************************************************
//**********************************************************************
//TEST FOR WRITING DATA PINS
uint8_t writeByte() {
uint8_t data = B;
for (int i = 0; i < 8; i++) {
int QP = bitRead(D, i); //Read each bit in the byte
data += QP;
//digitalWrite(Q0 + i, QP); //Set the pins to the value of each bit
//Serial.println(QP); //Test to print bits
}
PORTB = QP
//for (int i = Q0; i < Q0+8; i++) {
//if (bitRead(i) == HIGH) {
//data |= mask;
//}
//mask = mask << 1;
//}
//return data;
}
*/
void readChip() {
// Disable Chip, and disable read and write.
digitalWrite(CE, LOW);
DDRB = B00000000; //Set port "B" as input
for (int i = AD0; i < AD0+16; i++) {
digitalWrite(i,LOW);
pinMode(i, OUTPUT);
}
uint32_t addr = 0;
while (addr < MAX_ADDR) {
for (int i = 0; i < 16; i++) {
writeAddr(addr);
uint8_t b = PINB; //Read port "B" to a variable
Serial.print(b, HEX);
Serial.print(" ");
addr++;
}
Serial.println("");
}
while (1) {
}
}
void eraseChip() {
Serial.println(F("Chip would be erased"));
//***************************************
//All of this is commented out for safety
//***************************************
/*
pinMode(OES, HIGH);
pinMode(A9S, HIGH):
pinMode(CE, LOW);
delay(100);
pinMode(OES, LOW);
pinMode(A9S, LOW);
readChip();
*/
}
void burnChip() {
digitalWrite(CE, LOW); // Disable Chip, and disable read and write.
digitalWrite(OES, HIGH); //12v on OE
for (int i = AD0; i < AD0+16; i++) {
digitalWrite(i,LOW);
pinMode(i, OUTPUT);
}
DDRB = B11111111; //Set port "B" as output
for (uint32_t addr = 0; addr <= MAX_ADDR; addr++) {
int waiting = 0;
while(Serial.available() <= 0) {
//delay(2);
if (waiting == 0) {
delay(1);
Serial.println(F("NEXT")); // Tell Python script to send next byte
waiting = 1;
}
}
byte bval = 0;
if (Serial.available() > 0) {
delay(4);
//Start receiving data
char D = Serial.read(); //Read a byte
bval = (int) D;
//Serial.println(addr);
//Serial.println(D, HEX); //Test to see bytes getting to the arduino
for (int i = 0; i < 16; i++) {
writeAddr(addr);
//writeByte();
}
byte data;
for (int i = 0; i < 8; i++) {
int QP = bitRead(D, i); //Read each bit in the byte
data += QP;
//digitalWrite(Q0 + i, QP); //Set the pins to the value of each bit
//Serial.println(QP); //Test to print bits
}
}
//PORTB = data;
}
Serial.println(F("END")); //Send end command
}
void loop() {
if (Serial.available()) {
char ser = Serial.read();
if(ser == 'a'){
readChip();
}
else if(ser == 'b'){
eraseChip();
}
else if(ser == 'c'){
burnChip();
}
}
}