Created
August 19, 2014 18:04
-
-
Save misodengaku/b0f717a42675acfa3ef5 to your computer and use it in GitHub Desktop.
mbed W25Q32BV reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
SPI spi(p5, p6, p7); // mosi, miso, sclk | |
DigitalOut cs(p8); | |
Serial pc(USBTX, USBRX); | |
DigitalOut led[]={LED1,LED2,LED3,LED4}; | |
int main() { | |
char *p, *op; | |
int i, j, k; | |
unsigned int address = 0; | |
cs = 1; // disable | |
pc.baud(115200); | |
p = (char *)malloc(16384); // 16KB | |
op = p; | |
pc.printf("memory allocated.\r\n"); | |
spi.format(8,3); | |
spi.frequency(1000000); | |
pc.printf("spi mode changed.\r\n"); | |
cs = 0; // enable | |
for (i = 0; i < 4; i++) | |
{ | |
spi.write(0x90); // skip dummy | |
} | |
printf("manufacture id = 0x%X\r\n", spi.write(0x90)); | |
printf("device id = 0x%X\r\n\r\n", spi.write(0x90)); | |
cs = 1; // disable | |
for (i = 0; i < 256; i++) | |
{ | |
/* | |
pc.printf("Block %d/256\r\n", i + 1); | |
pc.printf("address: %X\r\n", address); | |
pc.printf("A23-A16: %02X\r\n", (address >> 16) & 0xFF); | |
pc.printf("A15-A8: %02X\r\n", (address >> 8) & 0xFF); | |
pc.printf("A7-A0: %02X\r\n", address & 0xFF); | |
wait(1); // debug | |
*/ | |
cs = 0; // enable | |
// Fast Read start | |
spi.write(0x0B); // instruction id | |
spi.write((address >> 16) & 0xFF); // 24bit address A23-A16 | |
spi.write((address >> 8) & 0xFF); // 24bit address A15-A8 | |
spi.write(address & 0xFF); // 24bit address A7-A0 | |
spi.write(0x00); // dummy | |
for (j = 0; j < 16384; j++) | |
{ | |
*p = spi.write(0x00); // dummy | |
p++; | |
} | |
p = op; // seek | |
for (j = 0; j < 16384; j++) | |
{ | |
pc.printf("%02X ", *p); // output | |
*p = 0; // clear buffer | |
p++; | |
} | |
pc.printf("\r\n"); | |
p = op; // seek | |
address += 16384; | |
cs = 1; // disable | |
led[i % 4] = !led[i % 4]; | |
} | |
pc.printf("Done.\r\n"); | |
led[0] = 0; | |
led[1] = 0; | |
led[2] = 0; | |
led[3] = 0; | |
while(1) | |
{ | |
led[0] = !led[0]; | |
led[1] = !led[1]; | |
led[2] = !led[2]; | |
led[3] = !led[3]; | |
wait(1); | |
} //trap | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment