Hello, I buy recently this 23LC1024 which is a SRAM chip.
I followed a tutorial in which the testing program had only: #include <SPI.h> in it. And it worked without problems. I actually tested with real arduino uno and in proteus simulator, with an arduino uno component there. Both worked.
-- I also read the datasheet chip as well and figure out from there [a way] of communicating with it. This part is exactly what I want to test.
-- My question here is: -can you give me a library that is writing in binary to one of arduino uno IO ports? I believe what the datasheet is telling me, is if I send a bunch of binary bits in a specific order, I might control this thing.
Understand my point well here, I want to make this communication as manual as possible, to actually see and understand what is going on. That is my whole intention. I already made it work with that SPI.h but everything is written behind and I am not that good at reading it back.
Thank you.
Here is what the datasheet for the binary sequence is saying:
Take a parallel output shift register and connect LEDs to the outputs and then use your own code to toggle bits one by one in and out of the shift register. That's what does SPI at a high clock rate.
Ok, thanks for the explanation. Then... it is possible to bit code it, without that fancy SPI.h library, right? Directly from the IO of the arduino uno. Right? Please tell me if im wrong.
Sure you can bit bang SPI.
Of course you can write a software SPI instead of using the SPI hardware. Take care to understand the SPI protocol before you start writing your own code.
Excellent answer mister @groundFungus ! You understood me correctly !
This is what I wanted ! Now, it is 90% good, since the rest of 10% is the actual implementation. I will update you with my progress and my mistakes that you can correct, since this specific chip has specific way of write/read to it as you can observe in the image I posted. Thank you very much !
I couldn't make it work
Here is my code I tried:
#include "Arduino.h"
/************SRAM opcodes: commands to the 23LC1024 memory chip ******************/
#define wpin 12 // Write pin
#define rpin 11 // Read pin
#define cspin 10 // Chip Select
/************Global Variables*********************/
/******************* Function Prototypes **************************/
void setup(void) {
pinMode(wpin, INPUT);
pinMode(rpin, INPUT);
pinMode(cspin, OUTPUT);
digitalWrite(cspin,LOW); //ChiSelect should stay LOW all the time we are writing or reading
//---------Writing---------
pinMode(wpin, OUTPUT);
Serial.println("Transmititng data...");
//1st: 8bit initialization
digitalWrite(wpin, B00000010);
//2nd: 24bit address
digitalWrite(wpin, B0000000);
digitalWrite(wpin, B0000000);
digitalWrite(wpin, B0000001);
//3rd 8bit code
digitalWrite(wpin, B1110011);
//---------Reading---------
Serial.println("Receiving data:");
//1st: 8bit initialization
digitalWrite(rpin, B00000011);
//2nd: 24bit address
digitalWrite(rpin, B0000000);
digitalWrite(rpin, B0000000);
digitalWrite(rpin, B0000001);
//3rd 8bit code
digitalWrite(rpin, B1110011);
digitalRead(rpin);
Serial.println(rpin);
}
void loop() { // we have nothing to do in the loop
}
digitalWrite() only writes a single bit to a single pin. To output a 24bit address, you'll need something like 72 digitalWrite() calls. (24 for the data bits, 48 for the clock bits.)
You should structure your code somewhat like the way the SPI library is written.
Write a function that outputs a single bit (with associated clocking.)
Use that in a function that outputs a full byte.
Use that in a function that brackets an entire message with the chip-select signals.
void SoftSPI_wBit(dpin, cpin, bitval) {
digitalWrite(dpin, bitval);
digitalWrite(cpin, 1); // clock
digitalWrite(cpin, 0); // clock return
}
void SoftSPI_wByte(dpin, cpin, byteval) {
for (int i=0; i < 8; i++) {
SoftSPI_wBit(dpin, cpin, bitRead(byteval, i));
}
}
void SoftSPI_wAddress(dpin, cpin, uint32_t address) {
SoftSPI_wByte(dpin, cpin, (address>>16) & 0xFF); // high byte address
SoftSPI_wByte(dpin, cpin, (address>>8) & 0xFF); // middle byte address
SoftSPI_wByte(dpin, cpin, (addresss) & 0xFF); // low byte addres
}
(that is NOT complete or compileable code. Also Beware bit and byte order.)
I changed the code like this:
> //2nd: 24bit address
> //this is 00000000 00000000 00000001
> for(int i = 0; i < 71; i++) //72in total = 24 for the data bits, 48 for the clock bits
> {
> digitalWrite(rpin, 0);
> }
> //and 1 that is manual specific addressing
> digitalWrite(rpin, 1);
still no response in the console:
I should have at least "Transmititng data..." and "Receiving data:" strings from the code...
If you want to see serial output you must open the serial port with Serial.begin(9600);
If you want to post serial monitor output, copy the output by highlighting it and pressing ctrl-c to copy. Then paste into a post.
Please do not post images of code. Pictures of code is nearly worthless. Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
I understand what you are saying but I still have to get a simple result by hard coding this thing and see it work. After that step, I can automate as much as I want. But until this kind of automation you describe, I have to understand how to do it manually. This will be a 'bit bang' as mister @groundFungus directed me and he is very close to my original intention.
Heh, I am not showing 'the code' in a picture. I am showing the Output console it is empty and part of the code that is linked to.
I am using the triple ` to format the code into .
If you want to post serial monitor output, copy the output by highlighting it and pressing ctrl-c to copy. Then paste into a post.
There is still no Serial.begin(9600);
in the setup() section of the code.
ooooh, so you dont like my pictures eh?
alright then; Here is the output console now after I introduced your Serial.begin(9600);
04:32:35.171 -> Transmititng data...
04:32:35.205 -> Receiving data:
04:32:35.205 -> 11
I dont think Im getting the right output but Im getting something !
Here is the full code as it is corrected until now:
#include "Arduino.h"
/************SRAM opcodes: commands to the 23LC1024 memory chip ******************/
#define wpin 12 // Write pin
#define rpin 11 // Read pin
#define cspin 10 // Chip Select
/************Global Variables*********************/
/******************* Function Prototypes **************************/
void setup(void) {
Serial.begin(9600);
pinMode(wpin, INPUT);
pinMode(rpin, INPUT);
pinMode(cspin, OUTPUT);
digitalWrite(cspin,LOW); //ChiSelect should stay LOW all the time we are writing or reading
//---------Writing---------
pinMode(wpin, OUTPUT);
Serial.println("Transmititng data...");
//1st: 8bit initialization
digitalWrite(wpin, B00000010);
//2nd: 24bit address
for(int i = 0; i < 71; i++) //72in total = 24 for the data bits, 48 for the clock bits
{
digitalWrite(wpin, 0);
}
//and 1 that is manual specific addressing
digitalWrite(wpin, 1);
//3rd 8bit code
digitalWrite(wpin, B1110011);
//---------Reading---------
Serial.println("Receiving data:");
//1st: 8bit initialization
digitalWrite(rpin, B00000011);
//2nd: 24bit address
//this is 00000000 00000000 00000001
for(int i = 0; i < 71; i++) //72in total = 24 for the data bits, 48 for the clock bits
{
digitalWrite(rpin, 0);
}
//and 1 that is manual specific addressing
digitalWrite(rpin, 1);
//3rd 8bit code
digitalWrite(rpin, B1110011);
digitalRead(rpin);
Serial.println(rpin);
}
void loop() { // we have nothing to do in the loop
}
and here is the output on the console:
I modified the last part of the code into this:
int answer = 0;
//3rd 8bit code
digitalWrite(rpin, B1110011);
for(int i = 0; i < 8; i++) //read the last 8bit code
{
digitalRead(rpin);
answer+=rpin;
}
Serial.println(answer);
}
and I get this result in the console:
and hello mister @groundFungus to the chat here. Nice tips so far ! Very helpful.
so...pretty much what I am after is this:
- I send some hardcoded data, I read that data also hardcoded(or directly), and if I get the correct result in the console, then mission accomplished. Like you said, 'bit banged' style.
You still are not understanding what the digitalWrite function does.
digitalWrite(wpin, B1110011);
does NOT write 8 bits. The digitalWrite function writes one bit, a 0 or a 1.
To write one bit to the SRAM you need to transition the clock from low to high, while the clock output is high, send the data bit and transition the clock from high to low. To write a byte you do that 8 times. Then you need to send one byte command and one byte of data.
Aha... yes you are right, I dont completely understand this function yet.
But I start to get it now... damn... its a bit harder that anticipated.
I also dont know when the clock is high or low.
I presume it is in one of the 2 states imediatly after I write a code line (whatever it is) but I start to see that may be much more many clocks into 1 single instruction from this high level arduino code....
So its impossible to link exactly the clock at it's high state with the bit that must be transmitted ?