Hi All,
I’ve been trying to store some bytes in an ATMEL 93C46 (I pulled from an old router) and am having NO Luck… everything returns zeros.
I’ve read the datasheet from ATMEL… I (at least I think I) have wired the 93C46 up correctly… for 8 bit mode (ORG & GND to Ground, CS to pin 10, DI to 11, DO to 12, Vcc 5v, and SK to 13).
Can anyone see what I’m doing incorrectly?
Any help would be appreciated… and go easy on me… It’s been a while.
– mkpellegrino
Here’s my code…
#define SS 10 // 0b00000100
#define MOSI 11 // 0b00001000
#define MISO 12 // 0b00010000
#define SCK 13 // 0b00100000
#define SSb 0b00000100
#define MOSIb 0b00001000
#define MISOb 0b00010000
#define SCKb 0b00100000
int dataword;
void write(int data, int length)
{
for( int i = 0; i < length; i++ )
{
if( data & B00000001 )
{
PORTB |= (1 << SS) | (1 << SCK) | (1 << MOSI);
}
else
{
PORTB |= (1 << SS) | (1 << SCK);
}
strobe();
data = data >> 1;
}
PORTB &= ~(1 << SS);
}
void strobe()
{
PORTB &= ~(1 << SCK);
delay(1);
PORTB |= (1 << SCK);
}
int read( int addr )
{
PORTB |= ( 1 << SS );
write( 2, 2 );
write( addr, 7 );
uint8_t divider = 0x80;
dataword = 0x00;
for (int i=0;i<=7;i++)
{
if (PINB & B1)
{
dataword += dataword;
}
strobe();
divider = divider >> 1;
}
PORTB &= ~(1 << SS );
return (dataword);
}
void ewen()
{
PORTB |= ( 1 << SS );
write( 3, 4);
PORTB &= ~( 1 << SS );
}
void eral()
{
PORTB |= ( 1 << SS );
write( 2, 4);
PORTB &= ~( 1 << SS );
}
void wral()
{
PORTB |= ( 1 << SS );
write(1, 4 );
PORTB &= ~( 1 << SS );
}
void ewds()
{
PORTB |= ( 1 << SS );
write(0,4);
PORTB &= ~( 1 << SS );
}
void erase( int addr )
{
PORTB |= ( 1 << SS );
write( 3, 2 );
write( addr, 7 );
PORTB &= ~( 1 << SS );
}
void store( int addr, int data )
{
PORTB |= ( 1 << SS );
write( 1, 2 );
write( addr, 7);
write( data, 8 );
PORTB &= ~( 1 << SS );
}
void loop()
{
// Nada
}
void setup()
{
DDRB |= (1 << MOSI) | (1 << SCK) | (1 << SS);
pinMode( SS, OUTPUT );
pinMode( SCK, OUTPUT );
pinMode( MOSI, OUTPUT );
pinMode( MISO, INPUT );
ewen();
store( 1, 0xFF);
store( 2, 0xEE);
store( 3, 0x30);
store( 4, 0x60);
store( 5, 0x30);
for( int i =0; i<5; i++)
{
int x = read( i );
}
delay(500);
}