Hello,
today i received those SRAM chips used in the link I posted before (23K256).
Ive seen here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1290379685
that it already has been implemented a library for the arduino.
Because my board is different i took a look in the class the user "carl" has written and changed the parameters to my board.
this is the original code from carl for the teensy
#define setupSPI SPCR = 0x50 //Master mode, MSB first, SCK phase low, SCK idle low, clock/4
#define setupDDRB DDRB |= 0x2e //set SCK(13) MOSI(11) and SS1 , SS2 as outputs
#define selectSS1 PORTB &= ~0x04 //set the SS to 0 to select SRAM 1
#define deselectSS1 PORTB |= 0x04 //set the SS to 1 to deselect SRAM 1
#define selectSS2 PORTB &= ~0x02 //set the SS to 0 to select SRAM 2
#define deselectSS2 PORTB |= 0x02 //set the SS to 1 to deselect SRAM 2
this is how i adapted it to the teensy 1.0 (it doenst work yet)
#define setupSPI SPCR = 0x50 //Master mode, MSB first, SCK phase low, SCK idle low, clock/4
#define setupDDRB DDRB |= 0x7 //set SCK(13) MOSI(11) and SS1 , SS2 as outputs
#define setupDDRB DDRC |= 0x4
#define selectSS1 PORTB &= ~0x01 //set the SS to 0 to select SRAM 1
#define deselectSS1 PORTB |= 0x01 //set the SS to 1 to deselect SRAM 1
#define selectSS2 PORTC &= ~0x04 //set the SS to 0 to select SRAM 2
#define deselectSS2 PORTC |= 0x04 //set the SS to 1 to deselect SRAM 2
My SS1 Pin on the teensy is PB0 so i thought the binary to set this PiN as an output is just to set DDRB to 000 0001 thats (the bit on the right should be PB0 am I right?)
because the SCLK and MOSI PINS have to be outputs to the binary for DDRB is 0000 0111 which is the number 0x07 in Binary
for the other Bit stuff i did it the same way. But the test Program wont work
Do you think i have to change more in the code?
In the cpp file which contains the functions defined in the constructor of the .h file are some hex values too, but i dont know anything about them.
SRAM2class::SRAM2class() //constructor
{
setupDDRB;
setupSPI;
deselectSS1; //deselect if selected
deselectSS2; //deselect if selected
selectSS1; //setup SRAM1
RWdata(0x05);//read status register
int Sreg = RWdata(0xff);//get status value
deselectSS1;
if(Sreg != 0x41) //are we in sequential mode
{
selectSS1;
RWdata(0x01); //write to status reg
RWdata(0x41); //set sequencial mode
deselectSS1;
}//end of set sequential mode for SRAM1
selectSS2; //setup SRAM2
RWdata(0x05);//read status register
Sreg = RWdata(0xff);//get status value
deselectSS2;
if(Sreg != 0x41) //are we in sequential mode
{
selectSS2;
RWdata(0x01); //write to status reg
RWdata(0x41); //set sequencial mode
deselectSS2;
}//end of set sequential mode for SRAM2
}//end of constructor
void SRAM2class::writestream1(int address)
{
deselectSS1; //deselect if still selected
deselectSS2; //deselect if still selected
selectSS1; //select now
RWdata(0x02);//write to address
RWdata(address >> 8);//msb address
RWdata(address);//lsb address
}//end of write stream SRAM 1
void SRAM2class::writestream2(int address)
{
deselectSS1; //deselect if still selected
deselectSS2; //deselect if still selected
selectSS2; //select now
RWdata(0x02);//write to address
RWdata(address >> 8);//msb address
RWdata(address);//lsb address
}//end of write stream SRAM 2
void SRAM2class::readstream1(int address)
{
deselectSS1; //deselect if still selected
deselectSS2; //deselect if still selected
selectSS1; //select now
RWdata(0x03);//read from address
RWdata(address >> 8);//read from address
RWdata(address);
}//end of read stream SRAM1
void SRAM2class::readstream2(int address)
{
deselectSS2; //deselect if still selected
deselectSS1; //deselect if still selected
selectSS2; //select now
RWdata(0x03);//read from address
RWdata(address >> 8);//read from address
RWdata(address);
}//end of read stream SRAM2
void SRAM2class::closeRWstream(void)
{
deselectSS1; //deselect
deselectSS2; //deselect
}//end of close RW stream
byte SRAM2class::RWdata(byte data)
{
SPDR = data;
while (!(SPSR & _BV(SPIF)))
;
return SPDR;
}//end of RWdata
Does anyone see a Problem?
Another thing i am not sure with is:
carl used a 820 Ohm and 1.5kOhm voltage divider to get the 5 V signal from the arduino to 3,3V
Because i didnt have those values I took 6,2kOhm and 10kOhm.
is that too much ?