Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Memory.cpp
- Revision:
- 10:96b5e7dcc91f
- Parent:
- 9:2587f246bf48
- Parent:
- 5:2fa79108a29b
--- a/Memory.cpp Tue Apr 17 03:16:03 2018 +0000
+++ b/Memory.cpp Tue Apr 17 03:20:30 2018 +0000
@@ -114,9 +114,98 @@
printf("\nLength %i exceeds Max Length\n",length);
return address;
}
+<<<<<<< local
//printf("\n C1 ");
+=======
+
+ //Enable the memory for wiring. This segment is only required if not writing to the start of a page.
+ if(address%256!=0){
+ _cs_mem=1;
+ _cs_mem=0; //Selet memory
+ my_spi.write(06); //Set Write Enable flag in the status reg
+ _cs_mem=1; //Deslect memory
+ wait_us(10);
+ _cs_mem=0; //Selet memory
+ my_spi.write(0x02); //Send write comand
+ my_spi.write(address>>16); //Send high address byte
+ my_spi.write(address>>8); //Send middle adress byte
+ my_spi.write(address); //Send low address
+ }
+
+>>>>>>> other
for(int i =0; i<length; i++) {
- if(address%256==0) { //Handle start and end of pages
+ //Handle start and end of pages. aAt the page boundry the memory must be deselected and and re-enabled for writng to the next page.
+ if(address%256==0) {
+ _cs_mem=1;
+ wait_us(10);
+ //wait for the WIP bit to go low
+ _cs_mem=0; //Selet memory
+ my_spi.write(0x05); //Send read status register command
+ int byte1 = my_spi.write(dummy);//Send dummy byte to read status reg
+ while ((byte1&1)>0) {
+ wait_us(10);
+ my_spi.write(0x05); //Send read status register command
+ byte1 = my_spi.write(dummy);//Send dummy byte to read status reg
+ }
+ _cs_mem=1;
+ _cs_mem=0; //Selet memory
+ my_spi.write(06); //Set Write Enable flag in the status reg
+ _cs_mem=1; //Deslect memory
+ wait_us(10);
+ _cs_mem=0; //Selet memory
+ my_spi.write(0x02); //Send write comand
+ my_spi.write(address>>16); //Send high address byte
+ my_spi.write(address>>8); //Send middle adress byte
+ my_spi.write(address); //Send low address
+ }
+
+ my_spi.write(buffer[i]); //Write the value of the buffer to memory
+ wait_us(5);
+ address=address+1; //Increment address
+ }
+ _cs_mem=1;
+ return address;
+}
+
+/**
+ * Arrange the data to the NEW address for icon refreshing
+ */
+int Memory::arrangeData(SPI my_spi, int Address, int addressNew, int length)
+{
+ char value[length];
+ _cs_mem = 1; //Ensure cs is deselected
+ wait_us(10);
+ _cs_mem = 0; //memory is selected
+ my_spi.write(0x03); //Send read command
+ my_spi.write(Address>>16); //Send high address byte
+ my_spi.write(Address>>8); //Send mid address byte
+ my_spi.write(Address); //Send low address byte
+
+
+ for(int i =0; i <length; i++) {
+ value[i]= my_spi.write(dummy);//Send dummy byte to read out value ate Address
+ Address++;
+ }
+ _cs_mem = 1;
+
+ wait_us(10);//wait for command transfer
+
+ //Enable the memory for wiring. This segment is only required if not writing to the start of a page.
+ if(addressNew%256!=0){
+ _cs_mem=1;
+ _cs_mem=0; //Selet memory
+ my_spi.write(06); //Set Write Enable flag in the status reg
+ _cs_mem=1; //Deslect memory
+ wait_us(10);
+ _cs_mem=0; //Selet memory
+ my_spi.write(0x02); //Send write comand
+ my_spi.write(addressNew>>16); //Send high address byte
+ my_spi.write(addressNew>>8); //Send middle adress byte
+ my_spi.write(addressNew); //Send low address
+ }
+
+ for(int i =0; i<length; i++) {
+ if(addressNew%256==0) { //Handle start and end of pages
_cs_mem=1;
wait_us(10);
//printf("\n C2 ");
@@ -141,21 +230,30 @@
//printf("\n C5 ");
_cs_mem=0; //Selet memory
- my_spi.write(02); //Send read comand
- my_spi.write(address>>16); //Send high address byte
- my_spi.write(address>>8); //Send middle adress byte
- my_spi.write(address); //Send low address
+ my_spi.write(0x02); //Send read comand
+ my_spi.write(addressNew>>16); //Send high address byte
+ my_spi.write(addressNew>>8); //Send middle adress byte
+ my_spi.write(addressNew); //Send low address
}
+<<<<<<< local
//printf("\n C6 ");
my_spi.write(buffer[i]); //Write the calue of the buffer to memory
//printf("%i%i%i%i%i%i%i%i",sixtyBytes[i]>>7&&1,buffer[i]>>6&&1,buffer[i]>>5&&1,buffer[i]>>4&&1,buffer[i]>>3&&1,buffer[i]>>2&&1,buffer[i]>>1&&1,buffer[i]&&1);
+=======
+ my_spi.write(value[i]); //Write the calue of the buffer to memory
+>>>>>>> other
wait_us(5);
- address=address++; //Increment address
+ addressNew=addressNew+1; //Increment address
}
_cs_mem=1;
+<<<<<<< local
return address;
}
+=======
+ wait_ms(10); //Need to wait register response, otherwise will cause the output full of dummies
+ return addressNew;
+}>>>>>>> other