# 23LC1024 manual programming

**URL:** <https://forum.arduino.cc/t/23lc1024-manual-programming/1030464>\
**Category:** General Discussion\
**Created:** [September 10, 2022, 7:22am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464 "2022-09-10T07:22:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 10, 2022, 7:22am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/1 "2022-09-10T07:22:03Z")

</div>

Hello, I buy recently this [23LC1024](https://ww1.microchip.com/downloads/aemDocuments/documents/MPD/ProductDocuments/DataSheets/23A1024-23LC1024-1-Mbit-SPI-Serial-SRAM-with-SDI-and-SQI-Interface-DS20005142.pdf) 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:

 ![Screenshot_1](https://europe1.discourse-cdn.com/arduino/original/4X/7/b/d/7bde85c40f3aa5fe39e3201571e8e503cc67cc23.jpeg)

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 10, 2022, 9:43am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/2 "2022-09-10T09:43:07Z")

</div>

> [@q12](#):
>
> actually see and understand what is going on

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.

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 10, 2022, 6:12pm UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/3 "2022-09-10T18:12:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [September 10, 2022, 6:52pm UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/4 "2022-09-10T18:52:39Z")

</div>

Sure you can [bit bang SPI.](https://circuitdigest.com/article/introduction-to-bit-banging-spi-communication-in-arduino-via-bit-banging)

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 10, 2022, 6:53pm UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/5 "2022-09-10T18:53:13Z")

</div>

> [@q12](#):
>
> without that fancy SPI.h library, right?

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.

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 11, 2022, 12:30am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/6 "2022-09-11T00:30:05Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 12:00am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/7 "2022-09-12T00:00:53Z")

</div>

I couldn't make it work  
Here is my code I tried:

```cpp
#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
}

```

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [September 12, 2022, 12:40am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/8 "2022-09-12T00:40:12Z")

</div>

> [@q12](#):
>
> ```arduino
> //2nd: 24bit address
> digitalWrite(wpin, B0000000);
> digitalWrite(wpin, B0000000);
> digitalWrite(wpin, B0000001);
> 
> ```

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.

```arduino
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.)

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 12:54am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/9 "2022-09-12T00:54:32Z")

</div>

I changed the code like this:

```cpp
> //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...

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/0/f/c/0fcf34097b8e832a24f676cd2288b43ee7b5723a.png)

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [September 12, 2022, 1:27am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/10 "2022-09-12T01:27:59Z")

</div>

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](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems)** to see how to properly post code and some good information on making a good post.  
Use the [IDE autoformat tool](https://www.tutorialspoint.com/auto-format-code-in-arduino-ide) (ctrl-t or Tools, Auto format) before posting code in code tags.

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 1:29am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/11 "2022-09-12T01:29:06Z")

</div>

> [@westfw](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 1:31am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/12 "2022-09-12T01:31:46Z")

</div>

> [@groundFungus](#):
>
> Please do not post images of code.

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 .

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [September 12, 2022, 1:32am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/13 "2022-09-12T01:32:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 1:35am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/14 "2022-09-12T01:35:37Z")

</div>

ooooh, so you dont like my pictures eh?  
alright then; Here is the output console now after I introduced your `Serial.begin(9600);`

```cpp
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 !

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 1:38am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/15 "2022-09-12T01:38:54Z")

</div>

Here is the full code as it is corrected until now:

```cpp
#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:  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/3/0/0/3008e06285ef18f542a3bf38672205e14bcd40cf.png)

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 1:48am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/16 "2022-09-12T01:48:37Z")

</div>

I modified the last part of the code into this:

```cpp
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:  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/f/3/e/f3ed1a2f744034019926289648fd78ac644aead9.png)

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 1:55am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/17 "2022-09-12T01:55:07Z")

</div>

and hello mister @groundFungus to the chat here. Nice tips so far ! Very helpful.

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 2:01am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/18 "2022-09-12T02:01:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [September 12, 2022, 2:01am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/19 "2022-09-12T02:01:31Z")

</div>

You still are not understanding what the digitalWrite function does.

```cpp
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.

---

<div class="post-metadata">

**Author:** ![q12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/q12/32/829265_2.png) [@q12](https://forum.arduino.cc/u/q12)\
**Post date:** [September 12, 2022, 2:07am UTC](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464/20 "2022-09-12T02:07:02Z")

</div>

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 ?

[Next page](https://forum.arduino.cc/t/23lc1024-manual-programming/1030464.md?page=2)
