Mr.Bean
New member
Hello friends!
I'm finishing a personal project but I need more RAM because I need many large temporary variables. I investigated and discovered the chip 23LC1024 so I bought it.
I tested the chip with an Arduino UNO and worked perfectly . But when I tried the chip with Teensy and it did not work.
The error is the below
Teensy always reads the value 255 for the "for" loop. I am using Teensy 3.2 at 72 Mhz.
Obviously, for the Teensy , I set the " SPI.beginTransaction " function according to this page: https://www.pjrc.com/teensy/td_libs_SPI.html
The code I used to Teensy is as follows:
And the code that I used with Arduino is the same buy without the function SPI.beginTransaction (because Arduino works at 16 Mhz)
The code is very simple. It waits five seconds and then type a value i + 5 in the " i " position and then read in the "i" position to send it via the serial port.
Connections that I use to connect the RAM to Teensy are as follows:
23LC1024
-- Vcc --- HOLD --- SCK -- MOSI --
|
|)
|
-- CS --- MISO --- NC --- GND --
Teensy pins
Vcc and HOLD ---- 3.3V or 5V
SCK ----------- 13
MOSI ---------- 11
MISO ---------- 12
CS ------------ 10
Also I attached the circuit in Fritzing :
I think the problem is in the configuration of SPI. But I do not know what I'm doing wrong. I searched a lot of information but I have not found someone to explain how to communicate with this chip using Teensy.
I know the Teensy audio library can access this chip. For this reason I think that this RAM can be configured directly from your code without using the library. The reason not to use audio library for my project is because I want to declare variables and store there. And as far as I know the library does it is save a series of data to produce a delay effect in the Audo.
So after all this, what is my mistake?
If someone also has the same problem (or a similar problem) I would like to comment on it. Hopefully, together, we solve the problem
Regards!
I'm finishing a personal project but I need more RAM because I need many large temporary variables. I investigated and discovered the chip 23LC1024 so I bought it.
I tested the chip with an Arduino UNO and worked perfectly . But when I tried the chip with Teensy and it did not work.
The error is the below
Teensy always reads the value 255 for the "for" loop. I am using Teensy 3.2 at 72 Mhz.
Obviously, for the Teensy , I set the " SPI.beginTransaction " function according to this page: https://www.pjrc.com/teensy/td_libs_SPI.html
The code I used to Teensy is as follows:
Code:
#include <SPI.h>
#define SS 10
//Configuración SRAM
#define RDSR 5
#define WRSR 1
#define READ 3
#define WRITE 2
//Byte transfer functions
byte READ_RAM(uint32_t address) {
byte read_byte;
digitalWrite(SS, LOW); // Enables SPI communication
SPI.transfer(READ);
SPI.transfer((byte)(address >> 16) & 0xff);
SPI.transfer((byte)(address >> 8) & 0xff); // 0xff = 255 = 11111111
SPI.transfer((byte)address);
read_byte = SPI.transfer(0x00);
digitalWrite(SS, HIGH); // Disable the SPI communication
return read_byte;
}
void WRITE_RAM(uint32_t address, uint32_t data_byte) {
digitalWrite(SS, LOW); // Enables SPI communication
SPI.transfer(WRITE); // We put the RAM in write mode
/*
Serial.println(address,BIN);
Serial.println(0xff,BIN);
Serial.println(((byte)address>>16) & 0xff);
*/
SPI.transfer((byte)(address >> 16) & 0xff); // Select the direction
SPI.transfer((byte)(address >> 8) & 0xff); // in RAM where the data will be saved
SPI.transfer((byte)address);
SPI.transfer(data_byte); // We send the data to the RAM
digitalWrite(SS, HIGH); // Disable the SPI communication
}
void setup(void) {
uint32_t i;
byte value;
Serial.begin(9600);
SPI.begin();
SPI.beginTransaction(SPISettings (20000000, MSBFIRST, SPI_MODE0));
delay(1000);
Serial.println(1);
delay(1000);
Serial.println(2);
delay(1000);
Serial.println(3);
delay(1000);
Serial.println(4);
delay(1000);
Serial.println(5);
delay(1000);
for (i=0; i<40; i++) {
WRITE_RAM(i, i+5);
value = READ_RAM(i);
Serial.println((uint16_t)value);
}
}
void loop() {
}
And the code that I used with Arduino is the same buy without the function SPI.beginTransaction (because Arduino works at 16 Mhz)
The code is very simple. It waits five seconds and then type a value i + 5 in the " i " position and then read in the "i" position to send it via the serial port.
Connections that I use to connect the RAM to Teensy are as follows:
23LC1024
-- Vcc --- HOLD --- SCK -- MOSI --
|
|)
|
-- CS --- MISO --- NC --- GND --
Teensy pins
Vcc and HOLD ---- 3.3V or 5V
SCK ----------- 13
MOSI ---------- 11
MISO ---------- 12
CS ------------ 10
Also I attached the circuit in Fritzing :
I think the problem is in the configuration of SPI. But I do not know what I'm doing wrong. I searched a lot of information but I have not found someone to explain how to communicate with this chip using Teensy.
I know the Teensy audio library can access this chip. For this reason I think that this RAM can be configured directly from your code without using the library. The reason not to use audio library for my project is because I want to declare variables and store there. And as far as I know the library does it is save a series of data to produce a delay effect in the Audo.
So after all this, what is my mistake?
If someone also has the same problem (or a similar problem) I would like to comment on it. Hopefully, together, we solve the problem
Regards!