I have to use 23LC512 SRAM in a project.
I have tried a few 23LC512 libraries. One of them is attached.
I run the library and the sample code on the arduino nano card without any problems when the CS pin is connected to pin 10.
I make the same connections on the STM32F103C8T6 bluepill card as below, but I could not run it.
23LC512 STM32 board
MOSI ---> A7
MISO ---> A6
SCK ---> A5
CS ---> A4 (I also tried changing the const int SRAM_CS = 10; value for A3, and A2.)
I connected MCP3201 to the same SPI pins and SPI2 pins, it works smoothly. MCP4921 runs smoothly in both SPI1 and SPI2.
But this 23LC512 does not work on STM32 card.
Sample code is below.
Can you help me?
Code: Select all
#include <SPI.h>
#include <SPISRAM.h>
/*
SRAM Arduino
1 CS 10(CS)
2 SO 12(MISO)
3 - -
4 Vss GND
5 SI 11(MOSI)
6 SCK 13(SCK)
7 HOLD <-- 100k ohm -- 3.3V
8 Vcc 3.3V
*/
const int SRAM_CS = 2;
SPISRAM myRAM(SRAM_CS, SPISRAM::BUS_MBits); // CS pin
char buffer[128];
void setup() {
// pinMode(11, OUTPUT);
// digitalWrite(11, HIGH);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
Serial.begin(115200);
SPI.begin();
myRAM.begin();
Serial.println("Byte write...");
myRAM.write(0,'H');
myRAM.write(1,'e');
myRAM.write(2,'l');
myRAM.write(3,'l');
myRAM.write(4,'o');
myRAM.write(5,'-');
Serial.println("Byte read...");
Serial.println((char)myRAM.read(0));
Serial.println((char)myRAM.read(1));
Serial.println((char)myRAM.read(2));
Serial.println((char)myRAM.read(3));
Serial.println((char)myRAM.read(4));
Serial.println((char)myRAM.read(5));
Serial.println("\nByte write...");
myRAM.write(0x7FFC,'W');
myRAM.write(0x7FFD,'o');
myRAM.write(0x7FFE,'r');
myRAM.write(0x7FFF,'l');
myRAM.write(0x8000,'d');
myRAM.write(0x8001,'!');
myRAM.write(0x8002,'!');
Serial.println("Byte read...");
Serial.println((char)myRAM.read(0x7FFC));
Serial.println((char)myRAM.read(0x7FFD));
Serial.println((char)myRAM.read(0x7FFE));
Serial.println((char)myRAM.read(0x7FFF));
Serial.println((char)myRAM.read(0x8000));
Serial.println((char)myRAM.read(0x8001));
Serial.println((char)myRAM.read(0x8002));
Serial.println("\nseq write...");
int addr = 0x7F00;
myRAM.write(addr, (byte*)"Hello world!!", sizeof("Hello world!!"));
Serial.println("seq read...");
myRAM.read(addr, (byte*)buffer, sizeof(buffer));
Serial.println( buffer );
}
int err;
void loop()
{
long err = 0;
Serial.println("\nRandom read/write...");
for(int i=0; i < 20; i++){
int addr = i & 0x7fff;
byte val = i+1;
Serial.print( addr, HEX );
Serial.print( " " );
Serial.print( val, HEX );
myRAM.write(addr, val);
Serial.print( " " );
Serial.println( myRAM.read(addr), HEX );
if (val != myRAM.read(addr)) err++;
}
Serial.print("error count = ");
Serial.println(err);
delay(1000);
}